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

RE: Getting position while ignoring empty elements

Subject: RE: Getting position while ignoring empty elements
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Tue, 27 Apr 2004 14:34:16 +0100
xsl position empty
> Is it possible  to find the position of an element while ignoring all 
> elements containing no text. For example, given the following:
> 
> <furniture>
> <item>table</item>
> <item/>
> <item>chair</item>
> </furniture>
> 
> I would like to output:
> 
> Furniture
> 1. table
> 2. chair


Lots of ways, one being:

<xsl:template match="furniture">
  <xsl:for-each select="item[child::node()]">
    <xsl:value-of select="position()"/>. <xsl:value-of select="."/>
  </xsl:for-each>
</xsl:template>

The for-each will iterate over each <item> node that has a child node
(whitespace included).  The function position() will return the position
of the node within the set selected by the for-each.

cheers
andrew

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.