-
Notifications
You must be signed in to change notification settings - Fork 266
/
generate-structure-xml.xslt
120 lines (109 loc) · 4.65 KB
/
generate-structure-xml.xslt
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:wcag="https://www.w3.org/WAI/GL/"
exclude-result-prefixes="#all"
version="2.0">
<xsl:include href="base.xslt"/>
<xsl:function name="wcag:get-id">
<xsl:param name="el" />
<xsl:choose>
<xsl:when test="$el/@id"><xsl:value-of select="$el/@id"/></xsl:when>
<xsl:otherwise><xsl:value-of select="wcag:generate-id(wcag:find-heading($el))"/></xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:output method="xml" indent="yes"/>
<xsl:template name="id">
<xsl:attribute name="id" select="wcag:get-id(.)"/>
</xsl:template>
<xsl:template name="content">
<xsl:variable name="content"><xsl:copy-of select="*[not(name() = 'h1' or name() = 'h2' or name() = 'h3' or name() = 'h4' or name() = 'h5' or name() = 'h6' or name() = 'section' or @class = 'conformance-level' or @class = 'change')]"></xsl:copy-of></xsl:variable>
<content><xsl:copy-of select="$content"/></content>
<contenttext><xsl:value-of select="serialize($content)"/></contenttext>
</xsl:template>
<xsl:template match="html:html">
<guidelines lang="{@lang}">
<understanding>
<name>Introduction to Understanding WCAG <xsl:value-of select="$guidelines.version.decimal"/></name>
<file href="intro"/>
</understanding>
<understanding>
<name>Understanding Techniques for WCAG Success Criteria</name>
<file href="understanding-techniques"/>
</understanding>
<understanding>
<name>Understanding Test Rules for WCAG Success Criteria</name>
<file href="understanding-act-rules"/>
</understanding>
<xsl:apply-templates select="//html:section[@class='principle']"/>
<understanding>
<name>Understanding Conformance</name>
<file href="conformance"/>
</understanding>
<understanding>
<name>How to Refer to WCAG <xsl:value-of select="$guidelines.version.decimal"/> from Other Documents</name>
<file href="refer-to-wcag"/>
</understanding>
<understanding>
<name>Documenting Accessibility Support for Uses of a Web Technology</name>
<file href="documenting-accessibility-support"/>
</understanding>
<understanding>
<name>Understanding Metadata</name>
<file href="understanding-metadata"/>
</understanding>
<xsl:apply-templates select="//html:dfn"/>
</guidelines>
</xsl:template>
<xsl:template match="html:section[@class='principle']">
<principle>
<xsl:call-template name="id"/>
<version>WCAG20</version>
<num><xsl:number count="html:section[@class='principle']" format="1"/></num>
<name><xsl:value-of select="wcag:find-heading(.)"/></name>
<xsl:call-template name="content"/>
<xsl:apply-templates select="html:section"/>
</principle>
</xsl:template>
<xsl:template match="html:section[contains(@class, 'guideline')]">
<guideline>
<xsl:call-template name="id"/>
<version>
<xsl:choose>
<xsl:when test="@id = 'pointer-accessible'">WCAG21</xsl:when>
<xsl:otherwise>WCAG20</xsl:otherwise>
</xsl:choose>
</version>
<num><xsl:number level="multiple" count="html:section[contains(@class, 'principle')]|html:section[contains(@class, 'guideline')]" format="1.1"/></num>
<name><xsl:value-of select="wcag:find-heading(.)"/></name>
<xsl:call-template name="content"/>
<file href="{wcag:generate-id(wcag:find-heading(.))}"/>
<xsl:apply-templates select="html:section"/>
</guideline>
</xsl:template>
<xsl:template match="html:section[contains(@class, 'sc')]">
<success-criterion>
<xsl:call-template name="id"/>
<version>WCAG<xsl:value-of select="$versions.doc//id[@id = wcag:get-id(current())]/parent::version/@name"/></version>
<num><xsl:number level="multiple" count="html:section[contains(@class, 'principle')]|html:section[contains(@class, 'guideline')]|html:section[contains(@class, 'sc')]" format="1.1.1"/></num>
<name><xsl:value-of select="wcag:find-heading(.)"/></name>
<xsl:call-template name="content"/>
<level><xsl:value-of select="html:p[@class='conformance-level']"/></level>
<file href="{wcag:generate-id(wcag:find-heading(.))}"/>
</success-criterion>
</xsl:template>
<xsl:template match="html:dfn">
<xsl:variable name="alts" select="tokenize(@data-lt, '\|')"></xsl:variable>
<term>
<id><xsl:text>dfn-</xsl:text><xsl:value-of select="wcag:generate-id(.)"/></id>
<name><xsl:value-of select="lower-case(.)"/></name>
<xsl:for-each select="$alts">
<name><xsl:value-of select="lower-case(.)"/></name>
</xsl:for-each>
<definition>
<xsl:copy-of select="../following-sibling::html:dd[1]/node()"/>
</definition>
</term>
</xsl:template>
</xsl:stylesheet>