-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-technique-associations.xslt
111 lines (96 loc) · 3.46 KB
/
generate-technique-associations.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
<?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:import href="base.xslt"/>
<xsl:output method="xml" indent="yes"/>
<xsl:param name="understanding.dir">understanding/</xsl:param>
<xsl:template match="guidelines">
<associations>
<xsl:apply-templates select="//guideline"/>
</associations>
</xsl:template>
<xsl:template match="guideline | success-criterion">
<xsl:variable name="subpath">
<xsl:choose>
<xsl:when test="version = 'WCAG20'">20/</xsl:when>
<xsl:when test="version = 'WCAG21'">21/</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:copy>
<xsl:attribute name="id" select="@id"/>
<xsl:apply-templates select="document(resolve-uri(concat(file/@href, '.html'), concat($understanding.dir, $subpath)))">
<xsl:with-param name="meta" select="." tunnel="yes"/>
</xsl:apply-templates>
<xsl:apply-templates select="guideline | success-criterion"/>
</xsl:copy>
</xsl:template>
<xsl:template match="html:html">
<xsl:apply-templates select="descendant::html:section[@id = 'techniques']"/>
</xsl:template>
<xsl:template match="html:section[@id = 'techniques']">
<sufficient>
<xsl:apply-templates select="html:section[@id = 'sufficient']"/>
</sufficient>
<advisory>
<xsl:apply-templates select="html:section[@id = 'advisory']"/>
</advisory>
<failure>
<xsl:apply-templates select="html:section[@id = 'failure']"/>
</failure>
</xsl:template>
<xsl:template match="html:section[@id = 'sufficient' or @id = 'advisory' or @id = 'failure']">
<xsl:apply-templates select="html:ol | html:ul | html:section"/>
</xsl:template>
<xsl:template match="html:section[@class = 'situation']">
<situation>
<title><xsl:value-of select="wcag:find-heading(.)"/></title>
<xsl:apply-templates select="html:ol | html:ul"/>
</situation>
</xsl:template>
<xsl:template match="html:li[html:p]">
<xsl:apply-templates select="html:p"/>
</xsl:template>
<xsl:template match="html:li[not(html:p)] | html:li/html:p">
<xsl:choose>
<xsl:when test="count(html:a) > 1">
<and>
<xsl:apply-templates select="html:a"/>
<xsl:if test="html:ol or html:ul or ../html:ol or ../html:ul">
<using>
<xsl:apply-templates select="html:ol | html:ul | ../html:ol | ../html:ul"/>
</using>
</xsl:if>
</and>
</xsl:when>
<xsl:when test="count(html:a) = 1">
<xsl:apply-templates select="html:a"/>
</xsl:when>
<xsl:otherwise>
<technique>
<title><xsl:apply-templates/></title>
<xsl:if test="html:ol or html:ul or ../html:ol or ../html:ul">
<using>
<xsl:apply-templates select="html:ol | html:ul | ../html:ol | ../html:ul"/>
</using>
</xsl:if>
</technique>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="html:a[wcag:is-technique-link(.)]">
<xsl:variable name="tech-id" select="replace(@href, '^.*/([\w\d]*)(\.html)?$', '$1')"/>
<technique>
<xsl:attribute name="id"><xsl:value-of select="$tech-id"/></xsl:attribute>
<xsl:if test="../html:ol or ../html:ul or ../../html:ol or ../../html:ul">
<using>
<xsl:apply-templates select="../html:ol | ../html:ul | ../../html:ol | ../../html:ul"/>
</using>
</xsl:if>
</technique>
</xsl:template>
<xsl:template match="html:a"/>
</xsl:stylesheet>