Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

XSLT compute position of parent

Question posted by: =?ISO-8859-1?Q?St=E9phane_Mottelet?= (Guest) on June 27th, 2008 07:07 PM
Hi, I have the following problem

<stuff>
<e1>
...
</e1>
<e1>
<e2/>
</e1>
</stuff>

When I am in the context of node <e2/>
how can I compute the position of its
parent <e1/within <stuff(position=2 here) ?

Thanks for help.

S.
Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
June 27th, 2008
07:07 PM
#2

Re: XSLT compute position of parent
Stéphane Mottelet wrote:
Quote:
Hi, I have the following problem
>
<stuff>
<e1>
...
</e1>
<e1>
<e2/>
</e1>
</stuff>
>
When I am in the context of node <e2/>
how can I compute the position of its
parent <e1/within <stuff(position=2 here) ?


position depends on the current node list and that can be different
depending on select expressions. For instance in your sample above if
you have
<xsl:template match="stuff">
<xsl:apply-templates/>
</xsl:template>
then the second 'e1' element has position 4 as there is white space
between the 'stuff' element and the 'e1' elements.

So it is not clear what you understand the position to be, if you want
to count the siblings of the same node type and name then use e.g.
<xsl:template match="e2">
<xsl:value-of select="count(.. | ../preceding-sibling::e1)"/>
</xsl:template>

xsl:number can also be helpful, depending on your needs.




--

Martin Honnen
http://JavaScript.FAQTs.com/

=?ISO-8859-1?Q?St=E9phane_Mottelet?='s Avatar
=?ISO-8859-1?Q?St=E9phane_Mottelet?=
Guest
n/a Posts
June 27th, 2008
07:07 PM
#3

Re: XSLT compute position of parent
Martin Honnen a écrit :
Quote:
Stéphane Mottelet wrote:
Quote:
>Hi, I have the following problem
>>
><stuff>
> <e1>
> ...
> </e1>
> <e1>
> <e2/>
> </e1>
></stuff>
>>
>When I am in the context of node <e2/>
>how can I compute the position of its
>parent <e1/within <stuff(position=2 here) ?

>
position depends on the current node list and that can be different
depending on select expressions. For instance in your sample above if
you have
<xsl:template match="stuff">
<xsl:apply-templates/>
</xsl:template>
then the second 'e1' element has position 4 as there is white space
between the 'stuff' element and the 'e1' elements.
>
So it is not clear what you understand the position to be, if you want
to count the siblings of the same node type and name then use e.g.
<xsl:template match="e2">
<xsl:value-of select="count(.. | ../preceding-sibling::e1)"/>
</xsl:template>
>
xsl:number can also be helpful, depending on your needs.
>
>
>
>


thanks !

S.

 
Not the answer you were looking for? Post your question . . .
189,938 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors