Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you can't use XSLT 2.0, here is an XSLT 1.0 stylesheet that should produce the same result as the XSLT 2.0 stylesheet I posted earlier:</p> <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt; &lt;xsl:output indent="yes"/&gt; &lt;xsl:template match="ROOT"&gt; &lt;xsl:apply-templates select="*[1]" mode="nest"&gt; &lt;xsl:with-param name="level" select="1"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*[starts-with(local-name(), 'TITEL')]" mode="nest"&gt; &lt;xsl:param name="level"/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$level = substring-after(local-name(), 'TITEL')"&gt; &lt;xsl:element name="TITEL{$level}"&gt; &lt;xsl:apply-templates select="."/&gt; &lt;xsl:apply-templates select="following-sibling::*[1][not(starts-with(local-name(), concat('TITEL', $level)))]" mode="nest"&gt; &lt;xsl:with-param name="level" select="$level"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:element&gt; &lt;xsl:apply-templates select="following-sibling::*[starts-with(local-name(), concat('TITEL', $level))][1]" mode="nest"&gt; &lt;xsl:with-param name="level" select="$level"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:apply-templates select="." mode="nest"&gt; &lt;xsl:with-param name="level" select="$level + 1"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*[not(starts-with(local-name(), 'TITEL'))]" mode="nest"&gt; &lt;xsl:param name="level"/&gt; &lt;xsl:apply-templates select="."/&gt; &lt;xsl:apply-templates select="following-sibling::*[1][not(starts-with(local-name(), concat('TITEL', $level)))]" mode="nest"&gt; &lt;xsl:with-param name="level" select="$level"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;xsl:template match="@* | node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@* | node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*[starts-with(local-name(), 'TITEL')]"&gt; &lt;TITEL&gt; &lt;xsl:apply-templates select="@* | node()"/&gt; &lt;/TITEL&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload