0

Possible Duplicate:
Does xslt have split() function?

I want to tokenize a comma-separated variable in my XSL style sheet, then iterate over the tokens using for-each to print the value of each token, what's the best way to do this?

<xsl:variable name="columns" select="'EMPID,NAME,DEPT"/>

<xsl:for-each select=???/>
   <!-- print name of token -->
</xsl:for-each>
Community
  • 1
  • 1
raffian
  • 31,267
  • 26
  • 103
  • 174
  • I think I'm using 1.0, the XSLT compiler is complaining about str:tokenize() – raffian Nov 03 '11 at 15:21
  • If your are using XSLT 1.0, the next question would be "which XSLT engine?" – Nic Gibson Nov 03 '11 at 15:43
  • THis question isn't well defined at all. Please, provide: 1. The complete (as small as possible) XML document; 2. The complete wanted result; 3. Explanation of the rules how the result should be produced from the XML document. – Dimitre Novatchev Nov 04 '11 at 01:31
  • @DimitreNovatchev You're right, this question is a duplicate of the one you mentioned, but I don't agree with your characterization of my question not being clear, it was clear enough for other members to suggest relevant answers, unfortunately, those answers don't conform to the version of XSLT engine I'm using. – raffian Sep 19 '12 at 23:14

2 Answers2

2

Well with XSLT 2.0 you would simply use for-each select="tokenize($columns, ',')". With XSLT 1.0 you would need to check whether a similar EXSLT or other extension function is supported:

<xsl:for-each select="str:tokenize($columns, ',')" xmlns:str="http://exslt.org/strings">...</xsl:for-each>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • I tried using that, but it's not compiling. Says that select="tokenize($columns,',')" is not a valid Xpath expression, and select="str:tokenize($columns,',')" does not work either. – raffian Nov 03 '11 at 15:27
0

If you are using XSLT 1.0 and XPath 1.0 then you cannot write

<xsl:variable name="columns" select="'EMPID,NAME,DEPT"/>

(even allowing for the spurious single-quote :)

All you can do is write a recursive template that splits the string using XPath calls to string-before and string-after.

If you describe what you need to do in more detail, including real data, then perhaps we can help you.

Borodin
  • 126,100
  • 9
  • 70
  • 144