XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Julian GuySubject: XSL help needed for recursive nested list menu
Author: Julian Guy
Date: 27 Feb 2006 04:41 AM
I have an XML file like this:

<menu>
<page id="1" name="home" url="default.asp">
<page id="2" name="second level 1" url="">
<page id="5" name="third level 1" url="">
<page id="8" name="fourth level 1" url=""/>
<page id="9" name="fourth level 2" url=""/>
</page>
<page id="6" name="third level 2" url=""/>
<page id="7" name="third level 3" url=""/>
</page>
<page id="3" name="second level 2" url=""/>
<page id="4" name="second level 3" url=""/>
</page>
</menu>

I need to write an XSL that writes out an unordered HTML list for the section based on a parameter of the current page. So. If i'm on page with id="9" I need:

Code:

<ul>
<li class="parent"><a href="">second level 1</a>
<li class="parent"><a href="">third level 1</a>
<li><a href="">fourth level 1</a>
<li class="selected"><a href="">fourth level 2</a>
</li>
<li/><a href="">third level 2</a></li>
<li/><a href="">third level 3</a></li>
</li>
</ul>



I'm really stuck. I've got this far:

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>

<xsl:param name="pageId" />

<xsl:template match="page">
<ul>
<xsl:choose>
<xsl:when test="descendant-or-self::page[@id=$pageId]">

<li class="parent"><xsl:value-of select="@name"/><xsl:apply-templates select="page"/></li>
</xsl:when>
<xsl:otherwise>

<li><xsl:value-of select="@name"/><xsl:apply-templates select="page"/></li>
</xsl:otherwise>
</xsl:choose>
</ul>
</xsl:template>

</xsl:stylesheet>



Nearly but not quite. can anyone tell me how to limit it to match within a specified depth?

Posttop
Minollo I.Subject: XSL help needed for recursive nested list menu
Author: Minollo I.
Date: 27 Feb 2006 09:59 AM
Julian,
I'm not sure I understand your constraints.

Does something like this work any better for you?
<xsl:choose>
<xsl:when test="descendant-or-self::page[@id=$pageId]">
<li class="parent">
<xsl:value-of select="@name"/>
<xsl:apply-templates select="page"/>
</li>
</xsl:when>
<xsl:when test="preceding-sibling::page/page[@id=$pageId] or following-sibling::page/page[@id=$pageId]">
<li class="parent">
<xsl:value-of select="@name"/>
<xsl:apply-templates select="page"/>
</li>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="page"/>
</xsl:otherwise>
</xsl:choose>

From what you wrote, I couldn't understand what you are try to show/hide when specifying a specific page id, and if what you want to display is a flat or hierarchical list.

Minollo

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.