Select preceding or following node
How do I move through a node set? For example, I have 20 nodes named image. These are divided into 2 groups, by 2 distinct values set in the attribute "group" ie
<image group="1" />
<image group="2" />
When i select a node in group 1, how can I select either the preceding or following node in group 1 in the xml file.
I am trying to display each image individually, but have links to the preceding or following nodes. In short a kind of image gallery.
I have tried to use the axes commands precedent-sibling and following-sibling, but these select all preceding or following nodes.
thanks in advance for any help
Hope this helps
I guess we will assume this is a question about how to do this in DOM and not XSLT...
In DOM land there is no nice clean way to do what you want. I assume you have a nodeList object which you got from the children property of another node or somesuch.
Your best bet is to iterate through the nodeList object, which has a method, item(index) which will return the node with the given index, and a property, length which tells you how many items there are. So just use a for loop to sift through them and test each node you find to see if its got the property value you are interested in.
This sort of thing is a pain in the arse using DOM. Now some DOM implementations will let you use an XPath statement to create a nodeList, in which case XPath of the form
will select image elements which are children of the current element and have a group attribute who's value is 1.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)