Skip to content

Commit bd4d5f4

Browse files
authored
Merge pull request #248 from oreillymedia/TOOLSDEV-387-epub-accessbility
Add handling for required epub accessibility metadata in OPF template
2 parents d216d73 + 2d85d64 commit bd4d5f4

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

htmlbook-xsl/opf.xsl

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,100 @@
9191
</xsl:choose>
9292
</xsl:template>
9393

94+
<!-- Generic template for handling accessibility properties -->
95+
<xsl:template name="get.accessibility.property.xml">
96+
<xsl:param name="terms.to.process" select="''"/>
97+
<xsl:param name="property.type" select="'term'"/> <!-- 'term', 'feature', or 'hazard' -->
98+
<xsl:param name="first.call" select="1"/>
99+
<xsl:choose>
100+
<xsl:when test="$first.call = 1">
101+
<xsl:variable name="wrapper.element">
102+
<xsl:choose>
103+
<xsl:when test="$property.type = 'term'">e:accessibility-terms</xsl:when>
104+
<xsl:when test="$property.type = 'feature'">e:accessibility-features</xsl:when>
105+
<xsl:when test="$property.type = 'hazard'">e:accessibility-hazards</xsl:when>
106+
</xsl:choose>
107+
</xsl:variable>
108+
<xsl:element name="{$wrapper.element}">
109+
<xsl:call-template name="get.accessibility.property.xml">
110+
<xsl:with-param name="terms.to.process" select="$terms.to.process"/>
111+
<xsl:with-param name="property.type" select="$property.type"/>
112+
<xsl:with-param name="first.call" select="0"/>
113+
</xsl:call-template>
114+
</xsl:element>
115+
</xsl:when>
116+
<xsl:otherwise>
117+
<xsl:choose>
118+
<xsl:when test="normalize-space(substring-before($terms.to.process, '&#x0A;')) != ''">
119+
<xsl:variable name="term">
120+
<xsl:value-of select="normalize-space(substring-before($terms.to.process, '&#x0A;'))"/>
121+
</xsl:variable>
122+
<xsl:variable name="element.name">
123+
<xsl:choose>
124+
<xsl:when test="$property.type = 'term'">e:term</xsl:when>
125+
<xsl:when test="$property.type = 'feature'">e:feature</xsl:when>
126+
<xsl:when test="$property.type = 'hazard'">e:hazard</xsl:when>
127+
</xsl:choose>
128+
</xsl:variable>
129+
<xsl:element name="{$element.name}"><xsl:value-of select="$term"/></xsl:element>
130+
<xsl:if test="normalize-space(substring-after($terms.to.process, '&#x0A;')) != ''">
131+
<xsl:call-template name="get.accessibility.property.xml">
132+
<xsl:with-param name="terms.to.process" select="substring-after($terms.to.process, '&#x0A;')"/>
133+
<xsl:with-param name="property.type" select="$property.type"/>
134+
<xsl:with-param name="first.call" select="0"/>
135+
</xsl:call-template>
136+
</xsl:if>
137+
</xsl:when>
138+
<xsl:when test="normalize-space($terms.to.process) != ''">
139+
<xsl:variable name="term">
140+
<xsl:value-of select="normalize-space($terms.to.process)"/>
141+
</xsl:variable>
142+
<xsl:variable name="element.name">
143+
<xsl:choose>
144+
<xsl:when test="$property.type = 'term'">e:term</xsl:when>
145+
<xsl:when test="$property.type = 'feature'">e:feature</xsl:when>
146+
<xsl:when test="$property.type = 'hazard'">e:hazard</xsl:when>
147+
</xsl:choose>
148+
</xsl:variable>
149+
<xsl:element name="{$element.name}"><xsl:value-of select="$term"/></xsl:element>
150+
</xsl:when>
151+
</xsl:choose>
152+
</xsl:otherwise>
153+
</xsl:choose>
154+
</xsl:template>
155+
156+
<!-- Parameter for accessibility modes -->
157+
<xsl:variable name="accessibility.modes.list.xml">
158+
<xsl:call-template name="get.accessibility.property.xml">
159+
<xsl:with-param name="terms.to.process" select="$access.mode"/>
160+
<xsl:with-param name="property.type" select="'term'"/>
161+
</xsl:call-template>
162+
</xsl:variable>
163+
164+
<!-- Parameter for accessibility mode sufficient -->
165+
<xsl:variable name="accessibility.mode.sufficient.list.xml">
166+
<xsl:call-template name="get.accessibility.property.xml">
167+
<xsl:with-param name="terms.to.process" select="$access.mode.sufficient"/>
168+
<xsl:with-param name="property.type" select="'term'"/>
169+
</xsl:call-template>
170+
</xsl:variable>
171+
172+
<!-- Parameter for accessibility features -->
173+
<xsl:variable name="accessibility.features.list.xml">
174+
<xsl:call-template name="get.accessibility.property.xml">
175+
<xsl:with-param name="terms.to.process" select="$accessibility.feature"/>
176+
<xsl:with-param name="property.type" select="'feature'"/>
177+
</xsl:call-template>
178+
</xsl:variable>
179+
180+
<!-- Parameter for accessibility hazards -->
181+
<xsl:variable name="accessibility.hazards.list.xml">
182+
<xsl:call-template name="get.accessibility.property.xml">
183+
<xsl:with-param name="terms.to.process" select="$accessibility.hazard"/>
184+
<xsl:with-param name="property.type" select="'hazard'"/>
185+
</xsl:call-template>
186+
</xsl:variable>
187+
94188
<xsl:template name="generate.mimetype">
95189
<!-- Outputs "mimetype" file that meets EPUB 3.0 specifications: http://www.idpf.org/epub/30/spec/epub30-ocf.html#physical-container-zip-->
96190
<!-- Override this template if you want to customize mimetype output -->
@@ -379,6 +473,26 @@
379473
<xsl:if test="$metadata.ibooks-specified-fonts = 1">
380474
<meta property="ibooks:specified-fonts">true</meta>
381475
</xsl:if>
476+
477+
<!-- Generate schema:accessMode elements for each term -->
478+
<xsl:for-each select="exsl:node-set($accessibility.modes.list.xml)//e:term">
479+
<meta property="schema:accessMode"><xsl:value-of select="."/></meta>
480+
</xsl:for-each>
481+
482+
<!-- Generate schema:accessModeSufficient elements for each term -->
483+
<xsl:for-each select="exsl:node-set($accessibility.mode.sufficient.list.xml)//e:term">
484+
<meta property="schema:accessModeSufficient"><xsl:value-of select="."/></meta>
485+
</xsl:for-each>
486+
487+
<!-- Generate schema:accessibilityFeature elements for each feature -->
488+
<xsl:for-each select="exsl:node-set($accessibility.features.list.xml)//e:feature">
489+
<meta property="schema:accessibilityFeature"><xsl:value-of select="."/></meta>
490+
</xsl:for-each>
491+
492+
<!-- Generate schema:accessibilityHazard elements for each feature -->
493+
<xsl:for-each select="exsl:node-set($accessibility.hazards.list.xml)//e:hazard">
494+
<meta property="schema:accessibilityHazard"><xsl:value-of select="."/></meta>
495+
</xsl:for-each>
382496
</metadata>
383497
</xsl:template>
384498

0 commit comments

Comments
 (0)