Click to See Complete Forum and Search --> : Select preceding or following node


wastlinger
03-11-2003, 09:49 AM
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

either

<image group="1" />

or

<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

wastlinger

khalidali63
03-11-2003, 04:58 PM
node.previousSibling

node.nextSibling

Hope this helps

Khalid

Alhazred
03-15-2003, 12:05 PM
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

'image[@group="1"]'

will select image elements which are children of the current element and have a group attribute who's value is 1.