p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 (http://p2p.wrox.com/forumdisplay.php?f=398)
-   -   Finding position within group (http://p2p.wrox.com/showthread.php?t=93102)

tkuzzy June 17th, 2014 01:36 PM

Finding position within group
 
Hello:

Given the following XML:

<code>
<root>
<item @type="a">blah, blah, blah</item>
<item @type="b">blah, blah, blah</item>
<item @type="c">blah, blah, blah</item>
<item @type="a">blah, blah, blah</item>
<item @type="b">blah, blah, blah</item>
<item @type="c">blah, blah, blah</item>
<item @type="b">blah, blah, blah</item>
<item @type="c">blah, blah, blah</item>
</root>
</code>

I'm using for-each-group to get one <item> with type="a" followed by any number of <item>s with type="b" or type="c". The example above would represent two groups. The first 3 items would be a group, and the rest would be another group. I've got that part working using the following:
<code>
<xsl:for-each-group select="item" group-starting-with="*[@type="a"]">
</code>

However, I want to be able to identify the nth occurence of each type within the group. I want to know if it's the first type="b" or the 2nd and so on.

Trying to count using preceding-sibling isn't working, as it looks outside my current-group(). Is it possible to count occurrences within the group without disturbing the order? Thank you.


All times are GMT -4. The time now is 07:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.