Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are really close, you just need to move your <code>&lt;xsl:variable name="ID" select="@Id"/&gt;</code> and your <code>&lt;xsl:apply-templates select="//row[@ParentId=$ID]"/&gt;</code> outside of your <code>&lt;ul&gt;...&lt;/ul&gt;</code> statement.</p> <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt; &lt;xsl:template match="/"&gt; &lt;ul id="someid" class="menu"&gt; &lt;xsl:apply-templates select="root/row[not(@ParentId)]"/&gt; &lt;/ul&gt; &lt;/xsl:template&gt; &lt;xsl:template match="row"&gt; &lt;xsl:variable name="ID" select="@Id"/&gt; &lt;li&gt; &lt;xsl:attribute name="rel"&gt; &lt;xsl:value-of select="@Id"/&gt; &lt;/xsl:attribute&gt; &lt;xsl:value-of select="@Name"/&gt; &lt;/li&gt; &lt;xsl:if test="//row[@ParentId=$ID]"&gt; &lt;ul&gt; &lt;xsl:apply-templates select="//row[@ParentId=$ID]"/&gt; &lt;/ul&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>this produces the result I think you are looking for</p> <pre><code>&lt;ul id="someid" class="menu"&gt; &lt;li rel="2"&gt;data&lt;/li&gt; &lt;ul&gt; &lt;li rel="6"&gt;folder&lt;/li&gt; &lt;/ul&gt; &lt;li rel="3"&gt;people&lt;/li&gt; &lt;ul&gt; &lt;li rel="4"&gt;person&lt;/li&gt; &lt;li rel="7"&gt;thing&lt;/li&gt; &lt;/ul&gt; &lt;li rel="8"&gt;web&lt;/li&gt; &lt;ul&gt; &lt;li rel="9"&gt;link&lt;/li&gt; &lt;/ul&gt; &lt;/ul&gt; </code></pre> <p>this also removes the extra <code>&lt;ul&gt;</code> before the top level <code>&lt;li rel="2"&gt;</code></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