summaryrefslogtreecommitdiff
path: root/xslt/check_framework.xsl
blob: f4e8d017c88d69670266ff7e005c78078c665a1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?xml version="1.0" encoding="UTF-8"?>
<!--

    check_framework.xsl

    XSL stylesheet providing a framework for use by rule checking files.

    Author: Ian A. Young <ian@iay.org.uk>

-->
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <!--
        The stylesheet output will be a text file, which will probably be thrown
        away in any case.  The real output from the check is sent using the
        xsl:message element.
    -->
    <xsl:output method="text"/>


    <!--
        Common template to call to report an error on some element within an entity.
    -->
    <xsl:template name="error">
        <xsl:param name="m"/>
        <xsl:variable name="entity" select="ancestor-or-self::md:EntityDescriptor"/>
        <xsl:message terminate='no'>
            <xsl:text>[ERROR] </xsl:text>
            <!--
                If we're processing an aggregate, we need to indicate which
                individual entity we're dealing with.
            -->
            <xsl:if test="ancestor-or-self::md:EntitiesDescriptor">
                <!--
                    Use an ID if available, otherwise the entityID.
                -->
                <xsl:choose>
                    <xsl:when test="$entity/@ID">
                        <xsl:value-of select="$entity/@ID"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$entity/@entityID"/>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:text>: </xsl:text>
            </xsl:if>
            <xsl:value-of select="$m"/>
        </xsl:message>
    </xsl:template>


    <!--
        Common template to call to report a warning on some element within an entity.
    -->
    <xsl:template name="warning">
        <xsl:param name="m"/>
        <xsl:variable name="entity" select="ancestor-or-self::md:EntityDescriptor"/>
        <xsl:message terminate='no'>
            <xsl:text>[WARN] </xsl:text>
            <!--
                If we're processing an aggregate, we need to indicate which
                individual entity we're dealing with.
            -->
            <xsl:if test="ancestor-or-self::md:EntitiesDescriptor">
                <!--
                    Use an ID if available, otherwise the entityID.
                -->
                <xsl:choose>
                    <xsl:when test="$entity/@ID">
                        <xsl:value-of select="$entity/@ID"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$entity/@entityID"/>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:text>: </xsl:text>
            </xsl:if>
            <xsl:value-of select="$m"/>
        </xsl:message>
    </xsl:template>


    <!--
        Common template to call to report an informational message on some element within an entity.
    -->
    <xsl:template name="info">
        <xsl:param name="m"/>
        <xsl:variable name="entity" select="ancestor-or-self::md:EntityDescriptor"/>
        <xsl:message terminate='no'>
            <xsl:text>[INFO] </xsl:text>
            <!--
                If we're processing an aggregate, we need to indicate which
                individual entity we're dealing with.
            -->
            <xsl:if test="ancestor-or-self::md:EntitiesDescriptor">
                <!--
                    Use an ID if available, otherwise the entityID.
                -->
                <xsl:choose>
                    <xsl:when test="$entity/@ID">
                        <xsl:value-of select="$entity/@ID"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$entity/@entityID"/>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:text>: </xsl:text>
            </xsl:if>
            <xsl:value-of select="$m"/>
        </xsl:message>
    </xsl:template>


    <!-- Recurse down through all elements by default. -->
    <xsl:template match="*">
        <xsl:apply-templates select="node()|@*"/>
    </xsl:template>


    <!-- Discard text blocks, comments and attributes by default. -->
    <xsl:template match="text()|comment()|@*">
        <!-- do nothing -->
    </xsl:template>

</xsl:stylesheet>