is it possible declare a string array in XSLT 2.0?
I would like declare something as below:
<xsl:variable name="countries" select="('IT','EN','SP')" />
but doesn't work.
Thanks.
is it possible declare a string array in XSLT 2.0?
I would like declare something as below:
<xsl:variable name="countries" select="('IT','EN','SP')" />
but doesn't work.
Thanks.
There are no arrays in the data model that XSLT/XPath 2.0 work with. Your code <xsl:variable name="countries" select="('IT','EN','SP')" /> binds a sequence of string values to the variable named countries and you should be able to access single items with a positional predicate like e.g. $countries[2].
If you think you need arrays then you need to use XPath 3.1 where you can use <xsl:variable name="countries" select="['IT', 'EN', 'SP']"/>, see http://www.w3.org/TR/xpath-31/#id-arrays. I am not aware of any released XSLT processor that supports this, however, I think XQuery implementations like BaseX have already been upgraded to support this.
As long as you simply want to store three or more atomic values in a flat data type I don't see why you would need the new array feature, the sequence ('IT','EN','SP') should suffice. Arrays can be nested, sequences not, as (1, (2, 3), 4) results in a flat sequence (1, 2, 3, 4), so in case you needed a nested data structure (with primitive values like numbers or strings) you might need an array and have to wait until there is support for XPath 3.1, you can however always created an XML tree structure for nested data in current versions of XSLT.
tokenize($countries,','). As for XSLT 1.0, its data types are primitive values like strings, booleans and numbers and "complex" values like node sets and result tree fragments. There no sequences of strings in that data model, nor arrays of any type. If you want to store three string values then the closest is a node set of three elements, each containing one string. If you want values not selected in an input document then you need to create a result tree fragment and convert it into a node set with exsl:node-set.