Search code examples
arraysxsltxpathsplice

XSL: create an Array from a Delimited String


I have a string name "string Variable" = 'hello, hello, good Evening, good evening'. I want to create an array on which I can do a foreach with the values divided by commas.

tnks


Solution

  • XSLT and XPath don't have an array data type unless you happen to use XPath 3.1 with XSLT 3. However in XSLT and XPath since version 2 there is a tokenize function you can use with e.g. tokenize('hello, hello, good Evening, good evening', ',\s*') to get a sequence of strings you can then process like any other sequence, for instance with a for-each.