Reputation: 517
I'm taking an XML class online and I'm not entirely sure what the "$" is used for.
Specifically, here is a block from the text book..
<xsl:value-of select="key('agentID', $aID)" />
The dollar sign in front of aID is where I am confused. Why does it need to be there?
Upvotes: 19
Views: 14545
Reputation: 243479
This is actually an XPath rule -- thus it can be used in any XPath expression inside XSLT code.
The $
character is used as the first character in a variable (or parameter) reference within an XPath expression.
Thus:
$person
means: the xsl variable or parameter named person
.
If we use just:
person
this means something completely different: all children of the context node that are named person
Forgetting the $
before the variable name in a variable reference is one of the most frequent mistakes comited by XSLT programmers.
It is a good practice to use such names for variables or parameters, that visually indicate that the named object is a variable/parameter.
For example, I always prefix the name of a variable with v
and the name of the parameter with p
:
$vPerson
$pTable
Upvotes: 24