Note that there are some explanatory texts on larger screens.

plurals
  1. PONormalizing XML adjacency list model into HTML tree list
    primarykey
    data
    text
    <p>I've seen examples of transforming "adjacency model" XML but none that will do it quite right for a ul/li bullet list. Could someone give me a hint? It would be great if the solution could support typical adjacency model requirements and deal with multiple level nesting/recursion.</p> <p>If the XML is:</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;root&gt; &lt;row Id="2" Name="data" /&gt; &lt;row Id="3" Name="people" /&gt; &lt;row Id="4" Name="person" ParentId="3" /&gt; &lt;row Id="6" Name="folder" ParentId="2" /&gt; &lt;row Id="7" Name="thing" ParentId="3" /&gt; &lt;row Id="8" Name="web" /&gt; &lt;row Id="9" Name="link" ParentId="8" /&gt; &lt;/root&gt; </code></pre> <p>And I use something like:</p> <pre><code>&lt;?xml version="1.0"?&gt; &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;ul&gt; &lt;li&gt; &lt;xsl:variable name="ID" select="@Id"/&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;xsl:apply-templates select="//row[@ParentId=$ID]"/&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Then I get:</p> <pre><code>&lt;ul id="someid" class="menu"&gt; &lt;ul&gt; &lt;li rel="2"&gt; data&lt;ul&gt; &lt;li rel="6"&gt;folder&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li rel="3"&gt; people &lt;ul&gt; &lt;li rel="4"&gt;person&lt;/li&gt; &lt;/ul&gt;&lt;ul&gt; &lt;li rel="7"&gt;thing&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li rel="8"&gt; web&lt;ul&gt; &lt;li rel="9"&gt;link&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/ul&gt; </code></pre> <p>Note the extra close/open ul tags between the "person" and "thing" li's- shouldn't be there. I can see why it's happening but just not sure how to change the code to fix it.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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