Project

Profile

Help

How to connect?
Download (8.23 KB) Statistics
| Branch: | Revision:

he / tools / genElementDoc.xsl @ 01d6fdb6

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:el="http://www.saxonica.com/ns/doc/elements"
4
    xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax"
5
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
7
    xmlns:doc="http://www.saxonica.com/ns/doc" exclude-result-prefixes="xs el e xsi map doc"
8
    version="3.0">
9
    
10
    <!-- 
11
        2017-01-20 DL Added checks (and output messages) to compare lists of attributes defined in
12
        xsl-elements-src.xml and element-catalog.xml.
13
    -->
14

    
15
    <xsl:output method="xml" indent="yes"/>
16

    
17
    <xsl:variable name="catalog" select="doc(resolve-uri('element-catalog.xml', base-uri(/)))"
18
        doc:doc="The W3C Spec catalog that contains the syntax information for the elements in this section"/>
19
    <xsl:variable name="namespace" select="'http://www.w3.org/1999/XSL/Transform'"
20
        doc:doc="The namespace for these elements"/>
21

    
22
    <xsl:template match="article">
23
        <xsl:copy>
24
            <xsl:sequence select="@id|@title"/>
25
            <xsl:comment>Generated - <xsl:value-of select="current-dateTime()"/> from src/elements/xsl-elements-src.xml (the editable version)</xsl:comment>
26
            <xsl:apply-templates select="*" mode="#current"/>
27
        </xsl:copy>
28
    </xsl:template>
29

    
30
    <xsl:template match="@*|*|text()">
31
        <xsl:copy>
32
            <xsl:apply-templates select="node()|@*" mode="#current"/>
33
        </xsl:copy>
34
    </xsl:template>
35

    
36
    <xsl:template match="section">
37
        <xsl:copy>
38
            <xsl:sequence select="@id|@title"/>
39
            <!--<xsl:apply-templates select="el:xsl-element" mode="#current">
40
                <xsl:sort select="/name"/>
41
            </xsl:apply-templates>-->
42
            <xsl:apply-templates/>
43
        </xsl:copy>
44
    </xsl:template>
45

    
46
    <xsl:template match="el:xsl-element"
47
        xpath-default-namespace="http://www.saxonica.com/ns/doc/elements">
48
        <xsl-element xmlns="http://www.saxonica.com/ns/doc/elements">
49
            <xsl:variable name="atts"
50
                select="map:merge((attributes/attribute ! map:entry(xs:string(./@name),./(*|text()))))" as="map(xs:string,node()*)"/>
51
            <!--<xsl:message>xsl:<xsl:value-of select="name"/></xsl:message>-->
52
            <!--<xsl:message>attributes: <xsl:value-of select="map:keys($atts)"/></xsl:message>-->
53
            <name namespace="{$namespace}">
54
                <xsl:value-of select="name"/>
55
            </name>
56
            <xsl:variable name="element-in-catalog" select="$catalog//e:element-syntax[@name=current()/name]"/>
57
            
58
            <xsl:choose>
59
                <xsl:when test="empty($element-in-catalog)">
60
                    <xsl:message>xsl:<xsl:value-of select="name"/> element not found in catalog</xsl:message>
61
                    <!-- Special case for xsl:stream now renamed xsl:source-document -->
62
                    <xsl:if test="string(name) eq 'stream'">
63
                        <xsl:call-template name="element-syntax">
64
                            <xsl:with-param name="el-name" as="xs:string" select="'source-document'"/>
65
                            <xsl:with-param name="atts" as="map(xs:string,node()*)" select="$atts"/>
66
                            <xsl:with-param name="element-in-catalog" as="element()?"
67
                                select="$catalog//e:element-syntax[@name='source-document']"/>
68
                            <xsl:with-param name="current-element" as="element()" select="."/>
69
                        </xsl:call-template>
70
                    </xsl:if>
71
                </xsl:when>
72
                <xsl:otherwise>
73
                    <xsl:call-template name="element-syntax">
74
                        <xsl:with-param name="el-name" as="xs:string" select="string(name)"/>
75
                        <xsl:with-param name="atts" as="map(xs:string,node()*)" select="$atts"/>
76
                        <xsl:with-param name="element-in-catalog" as="element()" select="$element-in-catalog"/>
77
                        <xsl:with-param name="current-element" as="element()" select="."/>
78
                    </xsl:call-template>
79
                </xsl:otherwise>
80
            </xsl:choose>
81
            
82
            <xsl:apply-templates select="*" mode="#current"/>
83
        </xsl-element>
84
    </xsl:template>
85

    
86
    <xsl:template match="el:name|el:attributes"/>
87
    
88
    <xsl:template name="element-syntax">
89
        <xsl:param name="el-name" as="xs:string"/>
90
        <xsl:param name="atts" as="map(xs:string,node()*)"/>
91
        <xsl:param name="element-in-catalog" as="element()"/>
92
        <xsl:param name="current-element" as="element()"/>
93
        <element-syntax xmlns="http://www.saxonica.com/ns/doc/elements" name="{$el-name}">
94
            <xsl:for-each select="$element-in-catalog/e:attribute">
95
                <!--<xsl:message>@<xsl:value-of select="@name"/></xsl:message>-->
96
                <attribute xmlns="http://www.saxonica.com/ns/doc/elements">
97
                    <xsl:apply-templates select="@*" mode="#current"/>
98
                    <desc>
99
                        <xsl:sequence select="$atts(@name)"/>
100
                        <xsl:if test="empty($atts(@name))">
101
                            <xsl:message>**** <xsl:value-of select="concat('xsl:',$el-name,'/@',@name)"/> requires description</xsl:message>
102
                        </xsl:if>
103
                    </desc>
104
                    <xsl:apply-templates select="*" mode="#current"/>
105
                </attribute>
106
            </xsl:for-each>
107
            <xsl:for-each select="map:keys($atts)">
108
                <xsl:sort/>
109
                <xsl:if test="empty($element-in-catalog/e:attribute[@name = current()])">
110
                    <xsl:choose>
111
                        <xsl:when test="starts-with(current(), 'saxon:')">
112
                            <xsl:message>Extension attribute <xsl:value-of select="concat('xsl:',$el-name,'/@',current())"/></xsl:message>
113
                            <xsl:variable name="data-type"
114
                                select="string($current-element/el:attributes/el:attribute[@name=current()]/@data-type)"/>
115
                            <attribute xmlns="http://www.saxonica.com/ns/doc/elements" name="{current()}">
116
                                <desc>
117
                                    <xsl:sequence select="$atts(current())"/>
118
                                    <xsl:if test="empty($atts(current()))">
119
                                        <xsl:message>**** <xsl:value-of select="concat('xsl:',$el-name,'/@',current())"/> requires description</xsl:message>
120
                                    </xsl:if>
121
                                </desc>
122
                                <xsl:choose>
123
                                    <xsl:when test="matches($data-type, '\s+')">
124
                                        <xsl:for-each select="tokenize($data-type, '\s+')">
125
                                            <constant value="{.}"/>
126
                                        </xsl:for-each>
127
                                    </xsl:when>
128
                                    <xsl:otherwise>
129
                                        <data-type name="{$current-element/el:attributes/el:attribute[@name=current()]/@data-type}"/>
130
                                    </xsl:otherwise>
131
                                </xsl:choose>
132
                            </attribute>
133
                        </xsl:when>
134
                        <xsl:otherwise>
135
                            <xsl:message>** <xsl:value-of select="concat('xsl:',$el-name,'/@',current())"/> not in element-catalog</xsl:message>
136
                        </xsl:otherwise>
137
                    </xsl:choose>
138
                </xsl:if>
139
            </xsl:for-each>
140
            <xsl:apply-templates select="$element-in-catalog/(* except e:attribute)" mode="#current"/>
141
        </element-syntax>
142
    </xsl:template>
143

    
144
    <xsl:template match="e:*">
145
        <xsl:element name="{local-name(.)}" namespace="http://www.saxonica.com/ns/doc/elements">
146
            <xsl:apply-templates select="@*|*|text()" mode="#current"/>
147
        </xsl:element>
148
    </xsl:template>
149

    
150
    <xsl:template match="e:element">
151
        <content xmlns="http://www.saxonica.com/ns/doc/elements">
152
            <xsl:apply-templates select="@*|*|text()" mode="#current"/>
153
        </content>
154
    </xsl:template>
155

    
156

    
157
</xsl:stylesheet>
(11-11/15)