My XSL-file:
...
<div>
<xsl:choose>
<xsl:when test="count(ancestor::node()) = 1">
<h2>
</xsl:when>
<xsl:when test="count(ancestor::node()) = 2">
<h3>
</xsl:when>
</xsl:choose>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:copy-of select="title/node()"/>
<xsl:choose>
<xsl:when test="count(ancestor::node()) = 1">
</h2>
</xsl:when>
<xsl:when test="count(ancestor::node()) = 2">
</h3>
</xsl:when>
</xsl:choose>
</div>
I know that it is not allowed to split tags h2…/h2, h3…/h3 like this.
But how to do this correctly?
You could do this with a recursive template and generate the heading element dynamically.
For example, this input XML:
processed by this XSLT:
gives the following HTML: