473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

XSLT compute position of parent

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.
Jun 27 '08 #1
2 3594
Stéphane Mottelet wrote:
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/
Jun 27 '08 #2
Martin Honnen a écrit :
Stéphane Mottelet wrote:
>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.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jorn W Janneck | last post by:
hello everyone. i have the sort of question that makes me feel like i am missing the forest for the trees, so apologies if i am missing the blatantly obvious here. i am using saxon, and mostly...
2
by: Claudio Jolowicz | last post by:
How can XSLT stylesheets be used to edit, remove and add nodes specified by their position in the document tree? The XML document stores development tasks in a hierarchical way, i.e. tasks can...
1
by: Ralph Snart | last post by:
i'm trying to do the classic alternating table row colors trick. i can't use position() mod 2 in this case because sometimes the template is called but it decides not to print the particular...
2
by: FrankStallone | last post by:
I am just getting started in XML and I made my first xml, dtd and xslt file and XML spy said they were all valid and they worked. This was the xslt doc that worked. <?xml version="1.0"...
7
by: mike p. | last post by:
I have a docbook xml file, and am using standard docbook 1.61.3 xsl stylesheets to do xhtml transform. Transform works fine when using MSXML. When I try to do the following using asp.net 1.1: ...
5
by: Douglas Steen | last post by:
Here's what I have (in snippets) ** XML ** <parent> <child> <grandchild/> </child> </parent> ** XSLT ** <xsl:template match="/parent">
6
by: datamodel | last post by:
Hello I have an XML tree of which you can see a mini-version here: http://paste.uni.cc/11838 (the tree is actually over 30,000 levels deep) How do I count the depth of a given...
3
by: z1 | last post by:
hi- i am fooling around with soap and weather templates. for some reason either this if or select is failing. i am very new to xml and found this code at another site. i can show you the xml...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.