473,405 Members | 2,279 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,405 software developers and data experts.

XSLT: select n-th element (how to use position?)

Hello NG,

I have an XML document looking similiar to:

<document>
<section>
<group>
<symbol>...</symbol> <!-- n=1 -->
<symbol>...</symbol> <!-- n=2 -->
...
<symbol>...</symbol> <!-- n=x -->
</group>
<symbol>...</symbol> <!-- n=x+1 -->
<symbol>...</symbol> <!-- n=x+2 -->
...
<group>
</group>
...
</section>
<section>
</section>
...
</document>
I need to select the n-th symbol (and all subnodes),
where n is the symbol number in the whole document.

Is this possible? If it is how will I be able to
achieve this?

AFAIK position() starts counting with 1 for each
parent element - isn't it?

thanx in advance,
Gerald
Jul 20 '05 #1
2 1594


Gerald Aichholzer wrote:

I have an XML document looking similiar to:

<document>
<section>
<group>
<symbol>...</symbol> <!-- n=1 -->
<symbol>...</symbol> <!-- n=2 -->
...
<symbol>...</symbol> <!-- n=x -->
</group>
<symbol>...</symbol> <!-- n=x+1 -->
<symbol>...</symbol> <!-- n=x+2 -->
...
<group>
</group>
...
</section>
<section>
</section>
...
</document>
I need to select the n-th symbol (and all subnodes),
where n is the symbol number in the whole document.


You can always do
(//symbol)[last()]
to access the last of all <symbol> elements at all levels.
Perhaps
(/document/section//symbol)[last()]
is all you need with that XML.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Martin Honnen wrote:

Gerald Aichholzer wrote:
I have an XML document looking similiar to:

<document>
<section>
<group>
<symbol>...</symbol> <!-- n=1 -->
<symbol>...</symbol> <!-- n=2 -->
...
<symbol>...</symbol> <!-- n=x -->
</group>
<symbol>...</symbol> <!-- n=x+1 -->
<symbol>...</symbol> <!-- n=x+2 -->
...
<group>
</group>
...
</section>
<section>
</section>
...
</document>
I need to select the n-th symbol (and all subnodes),
where n is the symbol number in the whole document.

You can always do
(//symbol)[last()]
to access the last of all <symbol> elements at all levels.
Perhaps
(/document/section//symbol)[last()]
is all you need with that XML.


Thank you for your information. n is specifid in a
parameter. Now I'm using the following wich works:

(/document//symbol)[position()=$symbolpos]
Gerald
Jul 20 '05 #3

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

Similar topics

5
by: Jonathan | last post by:
Does anyone know if it's possible to force a 'select' element (or select1) to bind each selected value to a seperate element when written to a file, instead of just putting all the values in one...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
0
by: Marek Mänd | last post by:
+ How do I select element B that has specific "id" attribute, regardless of that element B position in the document tree, by a hover pseudo-class declaration, when the mouse hovers over element A ...
1
by: Marek Mänd | last post by:
<select multiple style="height:200px;"> <option>a <option>b </select> Why does Mozilla draw the vertical scrollbar to the SELECT html element? There is plenty of void room below two OPTIONs in...
4
by: Rithish | last post by:
Is there a way to obtain the height of a <SELECT> element dynamically, i.e. through javascript? I want to dynamically display a list box onFocus of a text box element. Also, if the list box...
1
by: araripe | last post by:
Hi, Does someone can help me with the following problem? I have a SELECT form tag, with some OPTIONS elements. I am using the following code to detect a click in the SELECT. .......
13
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD...
2
by: Rob Long | last post by:
Hi I have an HTML select element in my page and it's multiple property is disabled (one item at a time mode) but I still want to transfer all the items in the select to the server when the form...
5
by: Andy Chambers | last post by:
Hi, On both Opera and Firefox, getElementsByTagName doesn't find anything apart from <optionelements inside a select element. Why is this? Here's a page that demonstrates this behaviour. I'd...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.