Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your main problem is this line:</p> <pre><code>&lt;xsl:apply-templates select="//LI" /&gt; </code></pre> <p>This produces a list of all <code>&lt;LI&gt;</code> elements in the input, and thus creates a flat output list. You can use the built-in recursion and "move with the flow", like this:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" /&gt; &lt;xsl:template match="BODY"&gt; &lt;toc&gt; &lt;xsl:apply-templates select="OBJECT" /&gt; &lt;xsl:apply-templates select="UL" /&gt; &lt;/toc&gt; &lt;/xsl:template&gt; &lt;xsl:template match="UL"&gt; &lt;xsl:apply-templates select="LI" /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="LI"&gt; &lt;topic&gt; &lt;xsl:apply-templates select="OBJECT" /&gt; &lt;xsl:apply-templates select="UL" /&gt; &lt;/topic&gt; &lt;/xsl:template&gt; &lt;xsl:template match="OBJECT"&gt; &lt;xsl:apply-templates select="param" /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="OBJECT/param"&gt; &lt;xsl:variable name="attrName"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="@name = 'FrameName'"&gt;label&lt;/xsl:when&gt; &lt;xsl:when test="@name = 'Name'"&gt;label&lt;/xsl:when&gt; &lt;xsl:when test="@name = 'Local'"&gt;href&lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable&gt; &lt;xsl:if test="$attrName != ''"&gt; &lt;xsl:attribute name="{$attrName}"&gt; &lt;xsl:value-of select="@value" /&gt; &lt;/xsl:attribute&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>The output produced is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;toc label="contents"&gt; &lt;topic label="Title1" href="Ref1"&gt; &lt;topic label="Title 2" href="Ref2"&gt; &lt;topic label="Title3" href="Ref3"&gt;&lt;/topic&gt; &lt;topic label="Title4" href="Ref4"&gt;&lt;/topic&gt; &lt;/topic&gt; &lt;topic label="Title5" href="Ref5"&gt;&lt;/topic&gt; &lt;/topic&gt; &lt;topic label="Title6" href="Ref6"&gt;&lt;/topic&gt; &lt;/toc&gt; </code></pre> <p>Note that I replaced your "mode" templates whith an <code>&lt;xsl:choose&gt;</code>. The rest is fairly obvious, I think.</p>
 

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