What does a "//" mean in an xpath expressin?

E

eric.goforth

In an xsl stylesheet, I have

<xsl:when test="string-length(//mystuff) &gt; 0">
<xsl:attribute name="someattribute">blahblahblah</xsl:attribute>
</xsl:when>

In the xml that mystuff is several layers deep, does the // do a search
in the xpath?

<test>
<another_level>
<mystuff>testing123</mystuff>
</another_level>
</test>
 
E

eric.goforth

In an xsl stylesheet, I have

<xsl:when test="string-length(//mystuff) &gt; 0">
<xsl:attribute name="someattribute">blahblahblah</xsl:attribute>
</xsl:when>

In the xml that mystuff is several layers deep, does the // do a search
in the xpath?

<test>
<another_level>
<mystuff>testing123</mystuff>
</another_level>
</test>

Answering my own question, from the w3schools website:

Selecting Nodes

XPath uses path expressions to select nodes in an XML document. The
node is selected by following a path or steps. The most useful path
expressions are listed below:
Expression Description
nodename Selects all child nodes of the node
/ Selects from the root node
// Selects nodes in the document from the current node that match the
selection no matter where they are
.. Selects the current node
... Selects the parent of the current node
@ Selects attributes

I'd tried searching w3schools, Google Group, etc. But couldn't find
anything for the "//" string.

-Eric
 
J

Johannes Koch

<xsl:when test="string-length(//mystuff) &gt; 0">
<xsl:attribute name="someattribute">blahblahblah</xsl:attribute>
</xsl:when>

In the xml that mystuff is several layers deep, does the // do a search
in the xpath?

See the XPath 1.0 spec (<http://www.w3.org/TR/xpath#path-abbrev>):
//para selects all the para descendants of the document root and thus
selects all para elements in the same document as the context node
 
D

Dimitre Novatchev

The exact definition from the W3C spec:

"// is short for /descendant-or-self::node()/"

This means a number of things, one is that, obviously, "//" only by itself
is not a valid XPath expression.

The other, that is a very frequent mistake people make is that

//something[1]

is not the same as

(//something)[1]

and it's possible that

count(//something[1])

may be greater than one

Cheers,
Dimitre Novatchev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,859
Latest member
VallieMcKe

Latest Threads

Top