Loading...
 
JoiWiki » Developer » XML Based Tech » XSLT XPath Variable use XSLT XPath Variable use

XSLT XPath Variable use

XSLT XPath Variable use

 So in XSLT you can make use of variables and that's awesome!
 

Declaring your Variable

 Below is the code used to declare a variable called NodeDescVar which will be available within the section that holds the declaration. If you want a variable to be available throughout the document for example, you would declare the variable at the top of your doc.

<xsl:variable name="NodeDescVar" select=""/>

 

Getting Data Into your Variable

 You'll notice in the code snipped above that there's nothing in the select section, this is where the magic happens! in the example below we're taking the value of an attribute 'description' on a node named 'TargetNodeName' (snappy I know).

<xsl:variable name="NodeDescVar" select="//Node[@name='TargetNodeName']/@description"/>

 

Using your variable

 To use your shiny new variable try throwing one of these bad boys into the mix:

<xsl:value-of select="$NodeDescVar"/>

or you can test on your new variable to do something cool conditionally:

<xsl:if test="$NodeDescVar = 'NodeDescValue'">We have a boring description!</xsl:if>

 

 

 

 

 

 

 

 

Created by JBaker. Last Modification: Wednesday April 3, 2019 18:07:57 BST by JBaker.

Developer