<
xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:dtb=
"http://www.daisy.org/z3986/2005/dtbook/" version=
"2.0">
<
xsl:include href=
"recursive-copy.xsl"/>
<
xsl:include href=
"output.xsl"/>
<
xsl:template match=
"dtb:level1|dtb:level2|dtb:level3|dtb:level4|dtb:level5|dtb:level6">
<
xsl:param name=
"currentLevel" select=
"0"/>
<
xsl:choose>
<
xsl:when test=
"count(./dtb:level2|./dtb:level3|./dtb:level4|./dtb:level5|./dtb:level6)=count(child::*)">
<
xsl:apply-templates>
<
xsl:with-param name=
"currentLevel" select=
"$currentLevel"/>
</
xsl:apply-templates>
</
xsl:when>
<
xsl:otherwise>
<
xsl:element name=
"level{$currentLevel + 1}" namespace=
"http://www.daisy.org/z3986/2005/dtbook/">
<
xsl:copy-of select=
"@*"/>
<
xsl:apply-templates>
<
xsl:with-param name=
"currentLevel" select=
"$currentLevel+1"/>
</
xsl:apply-templates>
</
xsl:element>
</
xsl:otherwise>
</
xsl:choose>
</
xsl:template>
<
xsl:template match=
"dtb:h1|dtb:h2|dtb:h3|dtb:h4|dtb:h5|dtb:h6">
<
xsl:param name=
"currentLevel" select=
"0"/>
<
xsl:element name=
"h{$currentLevel}" namespace=
"http://www.daisy.org/z3986/2005/dtbook/">
<
xsl:copy-of select=
"@*"/>
<
xsl:apply-templates/>
</
xsl:element>
</
xsl:template>
</
xsl:stylesheet>