Re: [xsl] xpath confusion

Subject: Re: [xsl] xpath confusion
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 3 Jul 2003 11:00:43 +0100

there are 4 possible answers that a compliant system could give to

   XPath: "Root/Keys/Client[@id="abc"]/ descendant-or-self::node()" 
8, 6, 4 or 3

as there there is the Client node itself (as you used descendant-or-self
rather than child) plus 7, 5, 3 or 2 child nodes.

The child nodes are counted as follows:

7: Your XML preserves all white space and comments, and your stylesheet
   isn't discarding white space with xsl:strip-space

5: Your XML parser discards comments but white space is preserved

3: your parser keeps comments but the parser or stylesheet are
   discarding white space

2; your parser discards comments and teh parser or stylesheet is
   dicarding white space.




So it seems that you are discarding white space most likely you have
xsl:strip space somewhere or are using MSXML which takes a cavalier
attitute to (not) preserving space in the input document.



That assumption then explains your remaining queries
  XPath: "Root/Keys/Client[@id="abc"]/ descendant-or-self::comment()"
  selects 1 node

you have one child node, here descendant-or-self::comment
is the same as descendant::comment you don't get 1 extra node from the
current Client  node, as that isn't a comment.


  XPath: "Root/Keys/Client[@id="abc"]/ descendant-or-self::text()"
  selects 0 nodes. 
  
As above on the assumption you've discared the white space, there are no
text node children, and the Client node is an element not text so 0 it
is.


  I would like to select the 3 nodes <Client>, <a /> and <b />. Any help is
  appreciated.

  Root/Keys/Client[@id="abc"]/descendant-or-self::*

will select Client and its element children and return 3 nodes.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread