aspose file tools*
The moose likes Product and Other Certifications and the fly likes Confused with Xpath expression! Need Help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "Confused with Xpath expression! Need Help." Watch "Confused with Xpath expression! Need Help." New topic
Author

Confused with Xpath expression! Need Help.

Vivek Saxena
Ranch Hand

Joined: Apr 24, 2002
Posts: 58
Hi,
Following question is from "Test 3 " of XMLWhiz. I am having problem to
under stand the Xpath expression.

What is the difference between
"//a[(following::x)]"
&
"//a[(following::x=.)]"

I know with "//a[(following::x)]" we will get all "a" elements which has "x" as following element.
I have no idea about the expression
"//a[(following::x=.)]".
Please help me !

Thanks
[ March 10, 2003: Message edited by: Vivek Saxena ]
Vivek Saxena
Ranch Hand

Joined: Apr 24, 2002
Posts: 58
Any help would great!
Waiting.
Thanks
Raj Yelnare
Greenhorn

Joined: Apr 21, 2002
Posts: 10
When I did use the stylesheet as
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:element name='Root'>
<xsl:call-template name="v3"/>
</xsl:element></xsl:template>
<xsl:template name="v3">
<xsl:variable name="v3List" select="//a[not(following::x=.)] | //x[not(preceding::a=.)] "/>
<xsl:for-each select="$v3List"><a><xsl:value-of select="."/>
</a></xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The browser gave me
3432354
When I included the stylesheet as
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:element name='Root'>
<xsl:call-template name="v3"/>
</xsl:element></xsl:template>
<xsl:template name="v3">
<xsl:variable name="v3List" select="//a[not(following::x)] | //x[not(preceding::a=.)] "/>
<xsl:for-each select="$v3List"><a><xsl:value-of select="."/>
</a></xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The browser gave me
3454
Vivek Saxena
Ranch Hand

Joined: Apr 24, 2002
Posts: 58
This is what i don't understand. There is a difference between "//a[(following::x)]" &
"//a[(following::x=.)]"
but i am not able to find/define the difference in words.
Any help would be appreciated.
Thanks
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
//a[following::x]
Select all a elements which has x in its following axis.
//a[following::x = .]
Select all a elements which has x in its following axis and the x node value equals the node a's value.
Vivek Saxena
Ranch Hand

Joined: Apr 24, 2002
Posts: 58
Oh , Now i get it.
Thanks you Roseanne.
Thanks
 
wood burning stoves
 
subject: Confused with Xpath expression! Need Help.