<
xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:xs=
"http://www.w3.org/2001/XMLSchema" xmlns:f=
"http://www.daisy.org/ns/functions-internal" xmlns:pf=
"http://www.daisy.org/ns/functions" xmlns:diagram=
"http://www.daisy.org/ns/z3998/authoring/features/description/" xmlns:rend=
"http://www.daisy.org/ns/z3998/authoring/features/rend/" xmlns:m=
"http://www.w3.org/1998/Math/MathML" xmlns:epub=
"http://www.idpf.org/2007/ops" xmlns:its=
"http://www.w3.org/2005/11/its" xmlns:tts=
"http://www.daisy.org/ns/pipeline/tts" xmlns:xlink=
"http://www.w3.org/1999/xlink" xmlns=
"http://www.w3.org/1999/xhtml" version=
"2.0" xpath-default-namespace=
"http://www.daisy.org/ns/z3998/authoring/" exclude-result-prefixes=
"#all">
<
xsl:import href=
"zedai-vocab-utils.xsl"/>
<
xsl:output method=
"xhtml" doctype-system=
"about:legacy-compat" encoding=
"UTF-8" indent=
"yes"/>
<
xsl:param name=
"base" select=
"base-uri(/)"/>
<
xsl:key name=
"refs" match=
"*[@ref]" use=
"tokenize(@ref,'\s+')"/>
<
xsl:key name=
"described" match=
"*[@desc]" use=
"@desc"/>
<
xsl:template match=
"/">
<
xsl:call-template name=
"html">
<
xsl:with-param name=
"nodes" select=
"document/body/*"/>
</
xsl:call-template>
</
xsl:template>
<
xsl:template name=
"html">
<
xsl:param name=
"nodes" as=
"node()*"/>
<
xsl:variable name=
"lang" select=
"$nodes/ancestor::*/@xml:lang[1]"/>
<
xsl:variable name=
"lang" select=
"($lang,'en')[1]"/>
<
html xml:lang=
"{$lang}" lang=
"{$lang}">
<
xsl:apply-templates select=
"$nodes/ancestor::*/@its:dir[1]"/>
<
head>
<
meta charset=
"UTF-8"/>
<
title><
xsl:value-of select=
"$nodes[1]/ancestor::document/head/meta[@property=('dc:title','dcterms:title')]/@content"/></
title>
</
head>
<
body>
<
xsl:copy-of select=
"$nodes/ancestor-or-self::*/@tts:*"/>
<
xsl:apply-templates select=
"$nodes"/>
</
body>
</
html>
</
xsl:template>
<
xsl:template match=
"section">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
section>
</
xsl:template>
<
xsl:template match=
"bibliography">
<
section>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('bibliography',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates mode=
"bibliography"/>
</
section>
</
xsl:template>
<
xsl:template match=
"section" mode=
"bibliography">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"bibliography"/>
</
section>
</
xsl:template>
<
xsl:template match=
"entry" mode=
"bibliography">
<
div>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('biblioentry',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates/>
</
div>
</
xsl:template>
<
xsl:template match=
"cover">
<
section>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('cover',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates/>
</
section>
</
xsl:template>
<
xsl:template match=
"spine">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
section>
</
xsl:template>
<
xsl:template match=
"frontcover">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
section>
</
xsl:template>
<
xsl:template match=
"backcover">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
section>
</
xsl:template>
<
xsl:template match=
"flaps">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
section>
</
xsl:template>
<
xsl:template match=
"glossary">
<
section>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('glossary',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates mode=
"glossary"/>
</
section>
</
xsl:template>
<
xsl:template match=
"section" mode=
"glossary">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"glossary"/>
</
section>
</
xsl:template>
<
xsl:template match=
"entry" mode=
"glossary">
<
dt>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('glossterm',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates/>
</
dt>
</
xsl:template>
<
xsl:template match=
"index">
<
nav>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"index"/>
</
nav>
</
xsl:template>
<
xsl:template match=
"section" mode=
"index">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"glossary"/>
</
section>
</
xsl:template>
<
xsl:template match=
"entry" mode=
"index">
<
xsl:apply-templates/>
</
xsl:template>
<
xsl:template match=
"frontmatter">
<
section>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('frontmatter',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates/>
</
section>
</
xsl:template>
<
xsl:template match=
"bodymatter">
<
section>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('bodymatter',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates/>
</
section>
</
xsl:template>
<
xsl:template match=
"backmatter">
<
section>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('backmatter',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates/>
</
section>
</
xsl:template>
<
xsl:template match=
"toc">
<
nav>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('toc',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:for-each-group select=
"*" group-adjacent=
"empty(self::entry)">
<
xsl:choose>
<
xsl:when test=
"not(current-grouping-key())">
<
ul>
<
xsl:apply-templates mode=
"toc" select=
"current-group()"/>
</
ul>
</
xsl:when>
<
xsl:otherwise>
<
xsl:apply-templates mode=
"toc" select=
"current-group()"/>
</
xsl:otherwise>
</
xsl:choose>
</
xsl:for-each-group>
</
nav>
</
xsl:template>
<
xsl:template match=
"entry" mode=
"toc">
<
li>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
li>
</
xsl:template>
<
xsl:template match=
"block" mode=
"toc">
<
div>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"toc"/>
</
div>
</
xsl:template>
<
xsl:template match=
"section" mode=
"toc">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"toc"/>
</
section>
</
xsl:template>
<
xsl:template match=
"aside" mode=
"toc">
<
aside>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"toc"/>
</
aside>
</
xsl:template>
<
xsl:template match=
"verse">
<
div>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
div>
</
xsl:template>
<
xsl:template match=
"section" mode=
"verse">
<
section>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"verse"/>
</
section>
</
xsl:template>
<
xsl:template match=
"block" mode=
"#all">
<
div>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
div>
</
xsl:template>
<
xsl:template match=
"block[f:has-role(.,'figure')]" mode=
"#all">
<
figure>
<
xsl:apply-templates select=
"@*"/>
<
xsl:variable name=
"objects" select=
"table|object"/>
<
xsl:variable name=
"captions" select=
".[@associate]/(hd|caption|citation)[not(@ref)] | (hd|caption|citation)[f:references-all(.,$objects)]"/>
<
xsl:if test=
"$captions[1] << $objects[1]">
<
figcaption>
<
xsl:apply-templates select=
"f:simplify-captions($captions)" mode=
"caption"/>
</
figcaption>
</
xsl:if>
<
xsl:apply-templates select=
"*"/>
<
xsl:if test=
"$captions[1] >> $objects[1]">
<
figcaption>
<
xsl:apply-templates select=
"f:simplify-captions($captions)" mode=
"caption"/>
</
figcaption>
</
xsl:if>
</
figure>
</
xsl:template>
<
xsl:template match=
"annotation" mode=
"#all">
<
aside epub:type=
"annotation">
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates/>
</
aside>
</
xsl:template>
<
xsl:template match=
"annoref" mode=
"#all">
<
a href=
"{@ref}">
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('annoref',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates select=
"if (@value) then @value else *"/>
</
a>
</
xsl:template>
<
xsl:template match=
"annoref/@value">
<
xsl:value-of select=
"."/>
</
xsl:template>
<
xsl:template match=
"aside" mode=
"#all">
<
aside>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
aside>
</
xsl:template>
<
xsl:template match=
"byline" mode=
"#all">
<
p>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
p>
</
xsl:template>
<
xsl:template match=
"caption" mode=
"#all"/>
<
xsl:template match=
"caption" mode=
"caption" priority=
"10">
<
xsl:choose>
<
xsl:when test=
"some $child in node() satisfies f:is-phrase($child)">
<
p>
<
xsl:apply-templates select=
"@*" mode=
"#default"/>
<
xsl:apply-templates mode=
"#default"/>
</
p>
</
xsl:when>
<
xsl:when test=
"@* except @ref">
<
div>
<
xsl:apply-templates select=
"@*" mode=
"#default"/>
<
xsl:apply-templates mode=
"#default"/>
</
div>
</
xsl:when>
<
xsl:otherwise>
<
xsl:apply-templates mode=
"#default"/>
</
xsl:otherwise>
</
xsl:choose>
</
xsl:template>
<
xsl:template match=
"citation" mode=
"#all">
<
xsl:if test=
"not(f:is-captioning(.))">
<
xsl:call-template name=
"citation"/>
</
xsl:if>
</
xsl:template>
<
xsl:template match=
"citation" mode=
"caption" priority=
"10">
<
xsl:call-template name=
"citation"/>
</
xsl:template>
<
xsl:template name=
"citation">
<
cite>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
cite>
</
xsl:template>
<
xsl:template match=
"code" mode=
"#all">
<
pre>
<
code>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"code"/>
</
code>
</
pre>
</
xsl:template>
<
xsl:template match=
"code[f:is-phrase(.)]">
<
code>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"code"/>
</
code>
</
xsl:template>
<
xsl:template match=
"lngroup" mode=
"code">
<
div>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('dsy:lngroup',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:apply-templates mode=
"code"/>
</
div>
</
xsl:template>
<
xsl:template match=
"dateline">
<
p>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
p>
</
xsl:template>
<
xsl:template match=
"definition">
<
p>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
p>
</
xsl:template>
<
xsl:template match=
"description[@xlink:href]" mode=
"#all">
<
xsl:message>[WARNING] Unsupported external description to '<
xsl:value-of select=
"@xlink:href"/>'.</
xsl:message>
</
xsl:template>
<
xsl:template match=
"description" mode=
"#all"/>
<
xsl:template match=
"description[key('described',@xml:id)[f:is-desc-unused(.)]]">
<
div>
<
xsl:apply-templates select=
"@*|node()"/>
</
div>
</
xsl:template>
<
xsl:template match=
"description" mode=
"details" priority=
"10">
<
xsl:choose>
<
xsl:when test=
"some $child in node() satisfies f:is-phrase($child)">
<
p>
<
xsl:apply-templates select=
"@*" mode=
"#default"/>
<
xsl:apply-templates mode=
"#default"/>
</
p>
</
xsl:when>
<
xsl:when test=
"@* except @ref">
<
div>
<
xsl:apply-templates select=
"@*" mode=
"#default"/>
<
xsl:apply-templates mode=
"#default"/>
</
div>
</
xsl:when>
<
xsl:otherwise>
<
xsl:apply-templates mode=
"#default"/>
</
xsl:otherwise>
</
xsl:choose>
</
xsl:template>
<
xsl:function name=
"f:description-string" as=
"xs:string">
<
xsl:param name=
"desc" as=
"element()?"/>
<
xsl:choose>
<
xsl:when test=
"some $child in $desc/node() satisfies f:is-phrase($child)">
<
xsl:sequence select=
"normalize-space(string($desc))"/>
</
xsl:when>
<
xsl:otherwise>
<
xsl:sequence select=
"string-join($desc/*/normalize-space(),' ')"/>
</
xsl:otherwise>
</
xsl:choose>
</
xsl:function>
<
xsl:template match=
"h" mode=
"#all">
<
xsl:element name=
"{if (hpart) then 'hgroup' else 'h1'}">
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
xsl:element>
</
xsl:template>
<
xsl:template match=
"hpart" mode=
"#all">
<
h1>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
h1>
</
xsl:template>
<
xsl:template match=
"hd" mode=
"#all">
<
xsl:if test=
"not(f:is-captioning(.))">
<
xsl:call-template name=
"hd"/>
</
xsl:if>
</
xsl:template>
<
xsl:template match=
"hd" mode=
"caption" priority=
"10">
<
xsl:call-template name=
"hd"/>
</
xsl:template>
<
xsl:template name=
"hd">
<
xsl:choose>
<
xsl:when test=
"parent::block[f:has-role(.,'figure')]">
<
h1>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
h1>
</
xsl:when>
<
xsl:otherwise>
<
p>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('bridgehead',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role" mode=
"#default"/>
<
xsl:apply-templates mode=
"#default"/>
</
p>
</
xsl:otherwise>
</
xsl:choose>
</
xsl:template>
<
xsl:template match=
"list" mode=
"#all">
<
xsl:apply-templates select=
"pagebreak[empty(preceding-sibling::item)]" mode=
"block"/>
<
xsl:element name=
"{if (@type='ordered') then 'ol' else 'ul'}">
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates select=
"* except pagebreak"/>
</
xsl:element>
<
xsl:apply-templates select=
"pagebreak[empty(following-sibling::item)]" mode=
"block"/>
</
xsl:template>
<
xsl:template match=
"list[@type='ordered']/@start">
<
xsl:copy/>
</
xsl:template>
<
xsl:template match=
"list[@type='ordered']/@rend:prefix">
<
xsl:choose>
<
xsl:when test=
"string(.)='decimal'">
<
xsl:attribute name=
"type" select=
"'1'"/>
</
xsl:when>
<
xsl:when test=
"string(.)='lower-alpha'">
<
xsl:attribute name=
"type" select=
"'a'"/>
</
xsl:when>
<
xsl:when test=
"string(.)='upper-alpha'">
<
xsl:attribute name=
"type" select=
"'A'"/>
</
xsl:when>
<
xsl:when test=
"string(.)='lower-roman'">
<
xsl:attribute name=
"type" select=
"'i'"/>
</
xsl:when>
<
xsl:when test=
"string(.)='upper-roman'">
<
xsl:attribute name=
"type" select=
"'I'"/>
</
xsl:when>
<
xsl:when test=
"string(.)=('decimal-leading-zero','lower-greek','upper-greek')">
<
xsl:attribute name=
"style" select=
"concat('list-style-type: ',string(.))"/>
</
xsl:when>
</
xsl:choose>
</
xsl:template>
<
xsl:template match=
"item" mode=
"#all">
<
li>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates select=
"preceding-sibling::pagebreak[exists(preceding-sibling::item) and current() is following-sibling::item[1]]"/>
<
xsl:apply-templates/>
</
li>
</
xsl:template>
<
xsl:template match=
"note">
<
aside>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
aside>
</
xsl:template>
<
xsl:template match=
"note/@role">
<
xsl:variable name=
"epub-type" select=
"pf:to-epub(.)"/>
<
xsl:if test=
"$epub-type">
<
xsl:attribute name=
"epub:type" select=
"$epub-type"/>
<
xsl:if test=
"$epub-type=('footnote','endnote')">
<
xsl:attribute name=
"role" select=
"concat('doc-',$epub-type)"/>
</
xsl:if>
</
xsl:if>
</
xsl:template>
<
xsl:template match=
"noteref">
<
a rel=
"note" href=
"{concat('#',@ref)}">
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('noteref',@role)"/>
</
xsl:call-template>
<
xsl:apply-templates select=
"@* except @role"/>
<
xsl:attribute name=
"role" select=
"'doc-noteref'"/>
<
xsl:choose>
<
xsl:when test=
"@value">
<
sup>
<
xsl:value-of select=
"@value"/>
</
sup>
</
xsl:when>
<
xsl:otherwise>
<
xsl:apply-templates/>
</
xsl:otherwise>
</
xsl:choose>
</
a>
</
xsl:template>
<
xsl:template match=
"object[f:is-image(.)]" mode=
"#all">
<
xsl:variable name=
"alt" as=
"xs:string?" select=
"f:description-string( if (description) then description else if (normalize-space(.)) then . else if (@desc) then id(tokenize(@desc,'\s+'))[not(@xlink:href)][1] else () )"/>
<
xsl:variable name=
"captions" select=
"../(hd|caption|citation)[f:references(.,current())]"/>
<
xsl:variable name=
"shared-captions" select=
"..[f:has-role(.,'figure')]/(hd|caption|citation)[f:references-all(.,../(object|table))]"/>
<
xsl:variable name=
"dedicated-captions" select=
"$captions except $shared-captions"/>
<
xsl:variable name=
"republisher-anno" select=
"key('refs',@xml:id)[self::annotation][@by='republisher'][1]"/>
<
xsl:choose>
<
xsl:when test=
"$dedicated-captions">
<
figure>
<
xsl:if test=
"$dedicated-captions[1] << .">
<
figcaption>
<
xsl:apply-templates select=
"f:simplify-captions($dedicated-captions)" mode=
"caption"/>
</
figcaption>
</
xsl:if>
<
img src=
"{@src}" alt=
"{$alt}">
<
xsl:apply-templates select=
"@*"/>
<
xsl:if test=
"f:is-desc-unused(.) or $republisher-anno">
<
xsl:attribute name=
"aria-describedby" select=
"if (f:is-desc-unused(.)) then @desc else $republisher-anno/@xml:id"/>
</
xsl:if>
</
img>
<
xsl:if test=
"$dedicated-captions[1] >> .">
<
figcaption>
<
xsl:apply-templates select=
"f:simplify-captions($dedicated-captions)" mode=
"caption"/>
</
figcaption>
</
xsl:if>
</
figure>
</
xsl:when>
<
xsl:otherwise>
<
img src=
"{@src}" alt=
"{$alt}">
<
xsl:apply-templates select=
"@*"/>
<
xsl:if test=
"f:is-desc-unused(.) or $republisher-anno">
<
xsl:attribute name=
"aria-describedby" select=
"if (f:is-desc-unused(.)) then @desc else $republisher-anno/@xml:id"/>
</
xsl:if>
</
img>
</
xsl:otherwise>
</
xsl:choose>
</
xsl:template>
<
xsl:template match=
"object" mode=
"#all">
<
xsl:message select=
"'object: unsupported media type'"/>
</
xsl:template>
<
xsl:template match=
"p">
<
p>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
p>
</
xsl:template>
<
xsl:template match=
"pagebreak" mode=
"block">
<
div>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('pagebreak',@role)"/>
</
xsl:call-template>
<
xsl:attribute name=
"role" select=
"'doc-pagebreak'"/>
<
xsl:apply-templates select=
"@* except @role"/>
</
div>
</
xsl:template>
<
xsl:template match=
"pagebreak">
<
span>
<
xsl:call-template name=
"role">
<
xsl:with-param name=
"roles" select=
"('pagebreak',@role)"/>
</
xsl:call-template>
<
xsl:attribute name=
"role" select=
"'doc-pagebreak'"/>
<
xsl:apply-templates select=
"@* except @role"/>
</
span>
</
xsl:template>
<
xsl:template match=
"pagebreak/@value" mode=
"#all">
<
xsl:attribute name=
"aria-label" select=
"concat(' ',.,'. ')"/>
</
xsl:template>
<
xsl:template match=
"quote">
<
blockquote>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
blockquote>
</
xsl:template>
<
xsl:template match=
"quote[f:is-phrase(.)]">
<
q>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates/>
</
q>
</
xsl:template>
<
xsl:template match=
"transition" mode=
"#all">
<
hr>
<
xsl:apply-templates select=
"@*"/>
</
hr>
</
xsl:template>
<
xsl:template match=
"table" mode=
"#all">
<
table>
<
xsl:apply-templates select=
"@*"/>
<
xsl:if test=
"not(parent::block[@role='figure'])">
<
xsl:variable name=
"captions" select=
"key('refs',@xml:id)[self::hd|self::caption]"/>
<
xsl:variable name=
"descs" select=
"id(tokenize(@desc,'\s+'))[not(@xlink:href)]"/>
<
xsl:if test=
"$captions or $descs">
<
caption>
<
xsl:apply-templates select=
"if (count($captions)=1 and $captions[self::caption]) then $captions/node() else $captions" mode=
"caption"/>
<
xsl:if test=
"$descs">
<
details>
<
summary>Description</
summary>
<
xsl:apply-templates select=
"$descs" mode=
"details"/>
</
details>
</
xsl:if>
</
caption>
</
xsl:if>
</
xsl:if>
<
xsl:apply-templates select=
"* except pagebreak"/>
</
table>
<
xsl:call-template name=
"table-final-pagebreaks"/>
</
xsl:template>
<
xsl:template match=
"colgroup" mode=
"#all">
<
colgroup>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates select=
"if(@span) then node() except col else node()"/>
</
colgroup>
</
xsl:template>
<
xsl:template match=
"col" mode=
"#all">
<
col>
<
xsl:apply-templates select=
"@*"/>
</
col>
</
xsl:template>
<
xsl:template match=
"colgroup/@span | col/@span" mode=
"#all">
<
xsl:copy/>
</
xsl:template>
<
xsl:template match=
"thead" mode=
"#all">
<
thead>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates select=
"* except pagebreak"/>
</
thead>
</
xsl:template>
<
xsl:template match=
"tbody" mode=
"#all">
<
tbody>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates select=
"* except pagebreak"/>
</
tbody>
</
xsl:template>
<
xsl:template match=
"tfoot" mode=
"#all">
<
tfoot>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates select=
"* except pagebreak"/>
</
tfoot>
</
xsl:template>
<
xsl:template match=
"tr" mode=
"#all">
<
tr>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates select=
"* except pagebreak"/>
</
tr>
</
xsl:template>
<
xsl:template name=
"th" match=
"th" mode=
"#all">
<
th>
<
xsl:apply-templates select=
"@*"/>
<
xsl:call-template name=
"table-incell-pagebreaks"/>
<
xsl:apply-templates/>
</
th>
</
xsl:template>
<
xsl:template match=
"td[@scope]" mode=
"#all">
<
xsl:call-template name=
"th"/>
</
xsl:template>
<
xsl:template match=
"td" mode=
"#all">
<
td>
<
xsl:apply-templates select=
"@*"/>
<
xsl:call-template name=
"table-incell-pagebreaks"/>
<
xsl:apply-templates/>
</
td>
</
xsl:template>
<
xsl:template match=
"@colspan|@rowspan|@scope|@headers" mode=
"#all">
<
xsl:copy/>
</
xsl:template>
<
xsl:template name=
"table-incell-pagebreaks">
<
xsl:if test=
"position()=1">
<
xsl:apply-templates select=
"../preceding-sibling::*[1][self::pagebreak]"/>
<
xsl:apply-templates select=
"../preceding-sibling::*[1][self::tr]/*[last()][self::pagebreak]"/>
</
xsl:if>
<
xsl:if test=
"position()=1 and not(../preceding-sibling::tr)">
<
xsl:apply-templates select=
"../parent::tbody/preceding-sibling::*[1][self::thead or self::tbody]/(*[last()]|*[last()]/*[last()])[self::pagebreak]"/>
<
xsl:apply-templates select=
"../parent::tfoot/preceding-sibling::*[1][self::tbody]/(*[last()]|*[last()]/*[last()])[self::pagebreak]"/>
</
xsl:if>
<
xsl:apply-templates select=
"preceding-sibling::*[1][self::pagebreak]"/>
</
xsl:template>
<
xsl:template name=
"table-final-pagebreaks">
<
xsl:apply-templates select=
"*[last()][self::pagebreak]" mode=
"block"/>
<
xsl:apply-templates select=
"*[last()][self::tr]/*[last()][self::pagebreak]" mode=
"block"/>
<
xsl:apply-templates select=
"*[last()][self::tbody|self::tfoot]/(*[last()]|*[last()]/*[last()])[self::pagebreak]" mode=
"block"/>
</
xsl:template>
<
xsl:template match=
"span" mode=
"#all">
<
span>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
span>
</
xsl:template>
<
xsl:template match=
"abbr" mode=
"#all">
<
abbr title=
"{normalize-space(id(@ref))}">
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
abbr>
</
xsl:template>
<
xsl:template match=
"expansion[not(ancestor::head)]" mode=
"#all">
<
span>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
span>
</
xsl:template>
<
xsl:template match=
"d" mode=
"#all">
<
span>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
span>
</
xsl:template>
<
xsl:template match=
"emph" mode=
"#all">
<
em>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
em>
</
xsl:template>
<
xsl:template match=
"ln" mode=
"#all">
<
span>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
span>
<
br/>
</
xsl:template>
<
xsl:template match=
"lnum" mode=
"#all">
<
span>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
span>
</
xsl:template>
<
xsl:template match=
"lngroup" mode=
"#all">
<
div>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
div>
</
xsl:template>
<
xsl:template match=
"ref" mode=
"#all">
<
a>
<
xsl:choose>
<
xsl:when test=
"@ref">
<
xsl:attribute name=
"href" select=
"concat('#',@ref)"/>
</
xsl:when>
<
xsl:when test=
"@xlink:href">
<
xsl:attribute name=
"href" select=
"@xlink:href"/>
<
xsl:attribute name=
"rel" select=
"'external'"/>
</
xsl:when>
</
xsl:choose>
<
xsl:apply-templates select=
"@* except (@ref,@xlink:href)"/>
<
xsl:apply-templates mode=
"#current"/>
</
a>
</
xsl:template>
<
xsl:template match=
"name" mode=
"#all">
<
i>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
i>
</
xsl:template>
<
xsl:template match=
"num" mode=
"#all">
<
span>
<
xsl:apply-templates select=
"@*"/>
<
xsl:if test=
"@value">
<
xsl:attribute name=
"title" select=
"@value"/>
</
xsl:if>
<
xsl:apply-templates mode=
"#current"/>
</
span>
</
xsl:template>
<
xsl:template match=
"s" mode=
"#all">
<
span>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
span>
</
xsl:template>
<
xsl:template match=
"term" mode=
"#all">
<
xsl:element name=
"{if (id(@ref)=(parent::*,preceding-sibling::*,following-sibling::*)) then 'dfn' else 'i'}">
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
xsl:element>
</
xsl:template>
<
xsl:template match=
"time" mode=
"#all">
<
time>
<
xsl:apply-templates select=
"@*"/>
<
xsl:if test=
"@time">
<
xsl:attribute name=
"datetime" select=
"@time"/>
</
xsl:if>
<
xsl:apply-templates mode=
"#current"/>
</
time>
</
xsl:template>
<
xsl:template match=
"w" mode=
"#all">
<
span>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
span>
</
xsl:template>
<
xsl:template match=
"wpart" mode=
"#all">
<
span>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
span>
</
xsl:template>
<
xsl:template match=
"sub" mode=
"#all">
<
sub>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
sub>
</
xsl:template>
<
xsl:template match=
"sup" mode=
"#all">
<
sup>
<
xsl:apply-templates select=
"@*"/>
<
xsl:apply-templates mode=
"#current"/>
</
sup>
</
xsl:template>
<
xsl:template match=
"m:*|m:*/@*">
<
xsl:copy copy-namespaces=
"no">
<
xsl:apply-templates select=
"node() | @*"/>
</
xsl:copy>
</
xsl:template>
<
xsl:template match=
"diagram:description">
<
aside>
<
xsl:apply-templates select=
"@*|node()"/>
</
aside>
</
xsl:template>
<
xsl:template match=
"diagram:body">
<
details>
<
xsl:apply-templates select=
"@*|node()"/>
</
details>
</
xsl:template>
<
xsl:template match=
"diagram:summary">
<
summary>
<
xsl:apply-templates select=
"@*|node()"/>
</
summary>
</
xsl:template>
<
xsl:template match=
"diagram:longdesc[not(*)]">
<
p>
<
xsl:value-of select=
"."/>
</
p>
</
xsl:template>
<
xsl:template match=
"comment()|processing-instruction()|text()">
<
xsl:copy/>
</
xsl:template>
<
xsl:template match=
"@xml:id">
<
xsl:attribute name=
"id" select=
"."/>
</
xsl:template>
<
xsl:template match=
"@base|@class|@xml:space|@xml:base|@xml:lang|@its:dir">
<
xsl:copy/>
</
xsl:template>
<
xsl:template match=
"@its:dir">
<
xsl:attribute name=
"dir" select=
"string(.)"/>
</
xsl:template>
<
xsl:template match=
"@role">
<
xsl:variable name=
"epub-type" select=
"pf:to-epub(.)"/>
<
xsl:if test=
"$epub-type">
<
xsl:attribute name=
"epub:type" select=
"$epub-type"/>
</
xsl:if>
</
xsl:template>
<
xsl:template match=
"@tts:*" mode=
"#all">
<
xsl:copy/>
</
xsl:template>
<
xsl:template match=
"@*" mode=
"#all"/>
<
xsl:template name=
"role">
<
xsl:param name=
"roles" as=
"xs:string*"/>
<
xsl:variable name=
"role-string" select=
"normalize-space(string-join($roles,' '))"/>
<
xsl:attribute name=
"epub:type" select=
"string-join(distinct-values(tokenize($role-string,'\s+')),' ')"/>
</
xsl:template>
<
xsl:function name=
"f:has-role" as=
"xs:boolean">
<
xsl:param name=
"elem" as=
"node()"/>
<
xsl:param name=
"role" as=
"xs:string*"/>
<
xsl:sequence select=
"tokenize($elem/@role,'\s+')=$role"/>
</
xsl:function>
<
xsl:function name=
"f:is-phrase" as=
"xs:boolean">
<
xsl:param name=
"node" as=
"node()"/>
<
xsl:sequence select=
"$node/self::text()[normalize-space()] or $node/preceding-sibling::text()[normalize-space()] or $node/following-sibling::text()[normalize-space()] or $node/parent::p"/>
</
xsl:function>
<
xsl:function name=
"f:is-block" as=
"xs:boolean">
<
xsl:param name=
"node" as=
"node()"/>
<
xsl:sequence select=
"$node/(self::p or self::block)"/>
</
xsl:function>
<
xsl:function name=
"f:is-image" as=
"xs:boolean">
<
xsl:param name=
"node" as=
"node()"/>
<
xsl:sequence select=
"starts-with($node/@srctype,'image/') or matches($node/@src,'\.(jpg|png|gif|svg)$') or matches($node/@src,'^data:image/')"/>
</
xsl:function>
<
xsl:function name=
"f:is-captioning" as=
"xs:boolean">
<
xsl:param name=
"elem" as=
"element()"/>
<
xsl:sequence select=
"$elem/../@associate or $elem/id(tokenize($elem/@ref,'\s+'))[self::table|self::object]"/>
</
xsl:function>
<
xsl:function name=
"f:references" as=
"xs:boolean">
<
xsl:param name=
"ref" as=
"element()"/>
<
xsl:param name=
"elems" as=
"element()*"/>
<
xsl:sequence select=
"$ref/@ref and tokenize($ref/@ref,'\s+')=$elems/@xml:id"/>
</
xsl:function>
<
xsl:function name=
"f:references-all" as=
"xs:boolean">
<
xsl:param name=
"ref" as=
"element()"/>
<
xsl:param name=
"elems" as=
"element()*"/>
<
xsl:sequence select=
"$ref/@ref and (every $id in $elems/@xml:id satisfies tokenize($ref/@ref,'\s+')=$id)"/>
</
xsl:function>
<
xsl:function name=
"f:simplify-captions" as=
"node()*">
<
xsl:param name=
"captions" as=
"element()*"/>
<
xsl:sequence select=
"if (count($captions)=1 and $captions[self::caption]) then $captions/node() else $captions"/>
</
xsl:function>
<
xsl:function name=
"f:is-desc-unused" as=
"xs:boolean">
<
xsl:param name=
"elem" as=
"element()"/>
<
xsl:sequence select=
"$elem/@desc and ($elem/description or normalize-space($elem))"/>
</
xsl:function>
</
xsl:stylesheet>