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

Re: Find the Position Index of Elements‏‏

Subject: Re: Find the Position Index of Elements‏‏
From: David Carlisle <davidc@xxxxxxxxx>
Date: Sun, 13 Jun 2010 22:48:51 +0100
Re:  Find the Position Index of  Elements‏‏
On 13/06/2010 20:43, Alice Wei wrote:

I have an XML snippet as in the following:

     <title>(I Just) Died In Your Arms</title>
     <album>80 Popular Hits</album>
     <artist>Cutting Crew</artist>
     <date added="03-24-2009"/>

This is one of the songs out of categories I have in my xml file, and
currently I use XPath expression as in the following:
/music_songs/song[category='Rock' as an example to find all the songs
in the Rock category.

whenever you use /a/b/c/[something='zzz']

you should think of doing


instead, it can be surprising the speedup you can get

I need to also be able to pull the position index of the song elements that I pull from the above expression, and use that in VB.NET for process. I tried using count(), position(), but they seem to be able to detect, but they cannot give me a list like

you don;t say if you are using xslt 1 or 2.

xslt 1 doesn't have a datatype that can store a sequence of integers.
You can get the numbers as for example

<xsl:for-each select="/music_songs/song[category='Rock']">

and then use


or <xsl:value-of select="count(preceding-sibling::song[category='Rock'])+1)"/>

Ib xslt2 you can store a list of integers


for example would work (although is paerhaps rather inefficient)


Current Thread


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.
First Name
Last Name
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.