Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6057233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:27:57+00:00 2026-05-23T08:27:57+00:00

I’ve seen examples of transforming adjacency model XML but none that will do it

  • 0

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.

If the XML is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
  <row Id="2" Name="data" />
  <row Id="3" Name="people" />
  <row Id="4" Name="person" ParentId="3" />
  <row Id="6" Name="folder" ParentId="2" />
  <row Id="7" Name="thing" ParentId="3" />
  <row Id="8" Name="web" />
  <row Id="9" Name="link" ParentId="8" />
</root>

And I use something like:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
<ul id="someid" class="menu">
  <xsl:apply-templates select="root/row[not(@ParentId)]"/>
</ul>
</xsl:template>

<xsl:template match="row">
<ul>
    <li>
    <xsl:variable name="ID" select="@Id"/>
      <xsl:attribute name="rel">
      <xsl:value-of select="@Id"/>
      </xsl:attribute>
      <xsl:value-of select="@Name"/>
      <xsl:apply-templates select="//row[@ParentId=$ID]"/>
   </li>
</ul>
</xsl:template>

</xsl:stylesheet>   

Then I get:

<ul id="someid" class="menu">
  <ul>
    <li rel="2">
      data<ul>
        <li rel="6">folder</li>
      </ul>
    </li>
  </ul>
  <ul>
    <li rel="3">
      people
      <ul>
        <li rel="4">person</li>
      </ul><ul>
        <li rel="7">thing</li>
      </ul>
    </li>
  </ul>
  <ul>
    <li rel="8">
      web<ul>
        <li rel="9">link</li>
      </ul>
    </li>
  </ul>
</ul>

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.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:27:58+00:00Added an answer on May 23, 2026 at 8:27 am

    Updated to reflect OP new requests

    This is a recursive template which does an HTML-compliant nested list as deinfed in the W3C specs.

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
        <xsl:output indent="yes"/>
    
        <xsl:template match="/root">
            <ul id="someid" class="menu">
                <xsl:apply-templates select="row[not(@ParentId)]"/>
            </ul>
        </xsl:template>
    
        <xsl:template match="row">
            <li rel="{@Id}">
                <xsl:value-of select="@Name"/>
                <xsl:if test="count(../row[@ParentId=current()/@Id])>0">
                    <ul>
                        <xsl:apply-templates select="../row[@ParentId=current()/@Id]"/>
                    </ul>
                </xsl:if>
            </li>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Applied on this input:

    <root>
      <row Id="1" Name="data" />
      <row Id="2" Name="data" />
      <row Id="3" Name="people" />
      <row Id="4" Name="person" ParentId="3" />
      <row Id="6" Name="folder" ParentId="2" />
      <row Id="7" Name="thing" ParentId="3" />
      <row Id="8" Name="web" />
      <row Id="9" Name="link" ParentId="8" />
        <row Id="10" Name="anotherone" ParentId="9" />
        <row Id="11" Name="anotherone" ParentId="9" />
        <row Id="12" Name="anotherone" ParentId="9" />
        <row Id="13" Name="anotherone" ParentId="3" />
    </root>
    

    Produces:

    <ul id="someid" class="menu">
       <li rel="1">data</li>
       <li rel="2">data<ul>
             <li rel="6">folder</li>
          </ul>
       </li>
       <li rel="3">people<ul>
             <li rel="4">person</li>
             <li rel="7">thing</li>
             <li rel="13">anotherone</li>
          </ul>
       </li>
       <li rel="8">web<ul>
             <li rel="9">link<ul>
                   <li rel="10">anotherone</li>
                   <li rel="11">anotherone</li>
                   <li rel="12">anotherone</li>
                </ul>
             </li>
          </ul>
       </li>
    </ul>
    

    If you are in trouble about how list should be created, try them at W3School.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.