[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Identify last node in nested nodeset with same name

Subject: Identify last node in nested nodeset with same name
From: Mat Bergman <matbergman@xxxxxxxxx>
Date: Thu, 23 Jun 2005 19:26:19 -0700 (PDT)
identify last name
I am working with XML data that shares the same
element name for each node set, for example:

<menu name="link1"/>
<menu name="link2">
     <menu name="link2a"/>
     <menu name="link2b"/>
</menu>

My XSL stylesheet transforms this into an HTML
unordered list, like this:
<ul>
<li>link1</li>
<li>link2
     <ul>
     <li>link2a</li>
     <li>link2b</li>
     </ul>
</li>
</ul>

I can't figure out how to identify the last
second-tier node (in this example "link2b") so that
the stylesheet can write the closing </ul> tag for the
nested list. I thought I would reference it with
something like <xsl:if test="/menu/menu[last()]">, but
my XPath must be incorrect because it fails.

I am currently writing the opening <ul> and closing
</li> tags for the nested list with this:

<xsl:template match="menu">
<xsl:if test="count(menu)>0">
<xsl:text>&lt;ul&gt;</xsl:text>
</xsl:if>

<xsl:if test="count(menu)=0">
<xsl:text>&lt;/li&gt;</xsl:text>
</xsl:if>
</xsl:template>

If I only knew how to identify the last node in
/menu/menu, I could easily write the closing tag.

Thanks,

-Mat




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.