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?
Introduction of XSLT for each. XSLT for each is defined as the iteration process that allows retrieving data from the specified nodes. Based on the selection criteria defined with these functions, it makes a loop through multiple nodes. This works in adding up with the function <xsl:value-of>.
XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.
XSLT <xsl:text> The <xsl:text> element is used to write literal text to the output. Tip: This element may contain literal text, entity references, and #PCDATA.
XSLT current() Function The current() function returns a node-set that contains only the current node. Usually the current node and the context node are the same.
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
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