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?
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:
means: the xsl variable or parameter named
person.If we use just:
this means something completely different: all children of the context node that are named
personForgetting 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
vand the name of the parameter withp: