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?
//
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With