Reputation: 5
I have a requirement where i have to save calculated values from each block of XML into a array like variable, i will use this array values for comparison later on in my XSLT code.
Can someone help in this that how can we save values in array in XSLT 1.0 or is there any other option to store such values.
Thanks, Mayank
Upvotes: 0
Views: 5842
Reputation: 167401
There are no arrays in XSLT, you have primitive values of type string, number, boolean and complex data types of a node-set of XML nodes and of result tree fragments in XSLT 1.0 and several more primitive data types in XSLT 2.0 and sequences of nodes and atomic items as the complex data type.
Thus if you want to store data in XSLT 1.0 you store it in a result tree fragment e.g.
<xsl:variable name="data-rtf">
<item>a</item>
<item>b</item>
</xsl:variable>
then to process it further you need to use exsl:node-set
or similar as in <xsl:variable name="data" select="exsl:node-set($data-rtf)" xmlns:exsl="http://exslt.org/common"/>
to have a node-set and then you can access e.g. $data/item[1]
, $data/item[2]
.
With XSLT 2.0 you don't need the exsl:node-set
or similar function, you can simply store data as a temporary tree (fragment) and access the nodes with XPath so you would use
<xsl:variable name="data">
<item>a</item>
<item>b</item>
</xsl:variable>
and then access $data/item[1]
, $data/item[2]
.
Upvotes: 3