Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] what index is the current item in a list?

From: "Lee Breisacher" <LBreisacher@------------------->
To:
Date: 8/2/2005 10:32:00 PM
Ah, preceding-sibling was the trick.  Thanks much!

Btw, I don't see how your first solution under 1.0 works - seems like it
would count the total number of type2 Items, not the "index" of this
particular type2 Item.

Lee


> -----Original Message-----
> From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
> Sent: Tuesday, August 02, 2005 1:19 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] what index is the current item in a list?
>
> In XSLT 2.0:
>
> <xsl:number select="parent::Item" count="*[Type='type2']"/>
>
> In 1.0:
>
> <xsl:for-each select="parent::Item">
>   <xsl:number count="*[Type='type2']"/>
> </xsl:for-each>
>
> Or if you prefer:
>
> count(parent::Item/preceding-sibling::*[Type='type2'])
>
> Michael Kay
> http://www.saxonica.com/
>
>
>
> > -----Original Message-----
> > From: Lee Breisacher [mailto:LBreisacher@xxxxxxxxxxxxxxxxxxx]
> > Sent: 02 August 2005 20:20
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: [xsl] what index is the current item in a list?
> >
> > 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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent