[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XPath question

Subject: XPath question
From: "Chris Robinson" <sipitai@xxxxxxxxxxx>
Date: Wed, 07 Jun 2006 19:08:55 +0800
xpath node contains
Hi everyone,

I have a XPath problem that "should" be reasonably easy to solve, but so far has just left me scratching my head.

Given the following XML*

<data>
 <a>
   <b/>
 </a>
 <a>
   <b>
     <c/>
   <b/>
 </a>
 <a>
   <b/>
   <b>
     <c/>
   <b/>
 </a>
</data>

* Note that this is just an example, the structure of the XML I'm working with changes each time. Having said that, there are always 1 or more "a" nodes, "a" nodes contain "b" nodes and there are always 1 or more "b" nodes, "b" nodes contain "c" nodes and a "c" node is either present or not present.

I am trying to create an XPath statement that selects the "c" node child of the first "b" node child (that has a "c" node child) of the first "a" node (that has a "b" node child, that in turn has a "c" node child). If that makes any sense :)

Note that I would just like to select 1 "c" node, as opposed to the set of "c" nodes.

I tried the following statement...

/data/a[1]/b[1]/c

....and while (if it works) it only selects 1 node, it just selects the first "a" node regardless of whether or not it contains a "b" node (and regardless of whether or not that "b" node contains a "c" node). In other words it only works if the first "a" node contains a "b" and that "b" node contains a "c" node, otherwise it fails.

I've tried so many variations on this statement that I've lost count, but so far I haven't been able to get it do what it needs to.

If anyone could let me know what the solution is here, or even just point me in the right direction, your assistance would be greatly appreciated.

Thanks!

_________________________________________________________________
realestate.com.au: the biggest address in property http://ninemsn.realestate.com.au


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.