dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Select preceding or following node

  1. #1
    Join Date
    Nov 2002
    Posts
    76

    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

    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

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    node.previousSibling

    node.nextSibling

    Hope this helps

    Khalid

  3. #3
    Join Date
    Mar 2003
    Location
    Burlington, Vermont
    Posts
    9
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles