File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question on Xpath

 
jim yin
Ranch Hand
Posts: 111
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is an example about "following" axis from an Xpath tutorial (Zvon), (1) and (2) are added by me to show the
results. (1) is easy to understand, why (2)? Thanks.
//ZZZ/following::*
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably confuse "following" axis with "descendant". What you expect is "descendant"; "following" means "all the nodes following the context node in the document order".
 
jim yin
Ranch Hand
Posts: 111
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Its more clear to me now. But why FFF is included, bit AAA is not?
Originally posted by Mapraputa Is:
You probably confuse "following" axis with "descendant". What you expect is "descendant"; "following" means "all the nodes following the context node in the document order".
 
Dan Drillich
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Part of the tree looks like -
AAA
/ \
/ \
BBB(1c) XXX
/ | \
/ | \
CCC ZZZ FFF(1a)(1b)
\
\
GGG
I denoted the text a bit differently. The three 1s became 1a, 1b and 1c.
When I ran the template in XML Spy -
<xsl:template match="/">
<xsl:apply-templates select="//ZZZ/following::*"/>
</xsl:template>
I got 1a, 1b and the 2s. I _didn't_ get 1c. I think 1c is a text node, which descends from BBB. It's not clear to me whether 1c follows ZZZ or not.
Any ideas?
Thanks,
Dan
 
Dan Drillich
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry ;-(
Let's try -
............AAA..............
........../....\.............
........./......\............
.........BBB(1c).XXX.........
......./..|.\................
....../...|..\...............
.....CCC.ZZZ.FFF(1a)(1b).....
...............\.............
................\............
...............GGG...........
 
Dan Drillich
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, the Apache Xalan XSLT processor gave me the same result (no 1c).
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what 1c is, but if it is empty element, you may not to get it in the output because it is empty.
Have you tried XPath Visualizer? Very tool.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mapraputa,
1C is text following the </FFF> tag. It will be held in a text node and its parent is BBB.
BBB, therefore, will have the following children (and maybe several empty text nodes), in this order - CCC,ZZZ,FFF and 1C. So, isn't 1C in the following axis of ZZZ?
Thanks,
Dan
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic