Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of $ in XSLT

Tags:

xml

xslt

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?

like image 219
jrounsav Avatar asked Nov 24 '12 00:11

jrounsav


People also ask

What is the use of for each in XSLT?

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>.

What is the purpose of an XSLT stylesheet?

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.

What is text () in XSLT?

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.

What is current () XSLT?

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.


1 Answers

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
like image 192
Dimitre Novatchev Avatar answered Sep 19 '22 19:09

Dimitre Novatchev