xml editor

Products

Features

  EPUB
Supported platforms

Supports Windows 7 & Mac OS X Lion

Ready for XML Editor data server software
W3C Member

// inside a predicate behaves like /descendant:: ???

Questions about XML that are not covered by the other forums should go here.

// inside a predicate behaves like /descendant:: ???

Postby schmidlinF » Wed Jun 17, 2009 12:51 pm

I this a bug or a feature of xpath?

the following xpath:
Code: Select all
/A/B[//C='want']


on the following XML:
Code: Select all
<A>
  <B><C>don't want</C></B>
  <B><C>want</C></B>
  <B><C>don't want</C></B>
</A>


returns 3 nodes instead of just the one.

to get the result I want I need to use
Code: Select all
/A/B[descendant::C='want']


I though
Code: Select all
//
was equivalent to
Code: Select all
descendant::
but inside a predicate it seems to be equivalent to
/descendant::
, i.e. select descendant nodes of the root element??

Have I missed something?

PS: example kept deliberately simple: please do not tell me I do not need // to get what I want :-)
schmidlinF
 
Posts: 1
Joined: Wed Jun 17, 2009 12:45 pm

Re: // inside a predicate behaves like /descendant:: ???

Postby sorin » Wed Jun 17, 2009 2:17 pm

Hello,

schmidlinF wrote:I though
Code: Select all
//
was equivalent to
Code: Select all
descendant::
but inside a predicate it seems to be equivalent to
/descendant::
, i.e. select descendant nodes of the root element??

Have I missed something?


It is equivalent to /descendant-or-self::node()/ as you can read in the XPath specification:

// is short for /descendant-or-self::node()/. For example, //para is short for /descendant-or-self::node()/child::para and so will select any para element in the document



Regards,
Sorin
sorin
 
Posts: 3228
Joined: Fri Mar 28, 2003 2:12 pm


Return to General XML Questions

Who is online

Users browsing this forum: No registered users and 0 guests

XML Editor | XML Author | WYSIWYG Editors | Schema Editor | XSD Documentation | XSL/XSLT Editor | XQuery | XML Databases | SVN Client
© 2002-2011 SyncRO Soft Ltd. All rights reserved. | Sitemap | Privacy Policy | This website was created & generated with <oXygen/>® XML Editor