Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of two forward slashes in xslt? "//"

Tags:

xml

xslt

I am in an XML class and have the following line of code..

<xsl:value-of select="count(//@qty)" />

What is the purpose of the "//" before the qty attribute? What does it designate?

like image 626
jrounsav Avatar asked Dec 10 '12 20:12

jrounsav


1 Answers

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

although in some expressions it acts similarly to descendant:: it is not the same. For example in the expression in the question

descendant::@qty

would be a syntax error as you can't have both the descendant and attribute axis in a single step.

/descendant-or-self::node()/@qty

on the other hand is a legal expression.

The other notable difference is //*[1] which selects every element that is the first child of its parent. whereas /descendant::*[1] selects the first element in the document.

like image 118
David Carlisle Avatar answered Oct 01 '22 03:10

David Carlisle