• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question on Xpath

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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::*
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW, the Apache Xalan XSLT processor gave me the same result (no 1c).
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic