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

what index is the current item in a list?

Subject: what index is the current item in a list?
From: "Lee Breisacher" <LBreisacher@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 2 Aug 2005 15:19:31 -0400
type2info
I want to do something that seems like it should be easy, but I cannot
figure it out.

I have a list of items like this in the input XML:

<Item>
   <Type>type1</Type>
   .. Other elements here..
</Item>
<Item>
   <Type>type2</Type>
   .. Other elements here..
</Item>
<Item>
   <Type>type1</Type>
   .. Other elements here..
</Item>
<Item>
   <Type>type3</Type>
   .. Other elements here..
</Item>
<Item>
   <Type>type2</Type>
   .. Other elements here..
</Item>

Each "Type" is handled differently, so the templates look like this:

<xsl:template match="*[Type = 'type1']">
	.. Do type1 stuff here..
</xsl:template>

<xsl:template match="*[Type = 'type2']">
	.. Do type2 stuff here..
</xsl:template>

<xsl:template match="*[Type = 'type3']">
	.. Do type3 stuff here..
</xsl:template>


Now, further down in the input XML is another list of items related to,
say, type2 Items, in the same order as in the Item list, like this:

<Type2Info>
    .. Elements related to the first type2 item is here..
</Type2Info>
<Type2Info>
    .. Elements related to the second type2 item is here..
</Type2Info>


So, I'm inside the second match template above and I want to get at the
proper Type2Info element. Logically, what I want to do is this:  "Get
the Nth Type2Info node where N is the ordinal number of the type2 Item
within the list of type2 Items."

I can make a list of just the type2 Items, that's easy. And I can access
the Nth Type2Info item, that's easy. I can even find the current type2
Item within the list of type2 Items, but I can't see how to determine
what N is. I've studied position() and xml:number and count(), etc. but
nothing seems quite what I need.

Help!

Thanks,

Lee

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.