how to make xsl tokenize work

匿名 (未验证) 提交于 2019-12-03 01:31:01

问题:

I have a huge xsl file but the section where i use "tokenize" to parse through a comma separated string is throwing an error. For simplicity purposes I have broke it down to just test the tokenize piece only and cannot seem to make any progress. I keep getting the following error:

Expression expected. tokenize(-->[<--text],',')

I tried using some example xsl shared in other posts but never managed to get it to work. I am having a difficult time understanding why my xsl code below is not valid. It seems t be very straightforward but I think I am missing something simple. Any help to get me in the right direction would be much appreciated.

XSL:

  

XML:

  Item1, Item2, Item3 

I am expecting an XML output as follows:

 Item1 Item2 Item3 

Thank you!

回答1:

As stated by DevNull, tokenize() is an XSLT 2.0 function. However, if your processor supports EXSLT, use can use the str:tokenize() function. Otherwise you will need to user recursion to split your comma separated values like thus ...

          


回答2:

I see 4 things wrong:

  1. You're using tokenize() in a 1.0 stylesheet. You need to change the version to 2.0 and use a 2.0 processor. If you're using a web browser to do the transform, based on the xml-stylesheet processing instruction, you're probably not using a 2.0 processor.

  2. The first argument of your tokenize ([text]) is invalid. Just use text.

  3. You've prematurely closed your xsl:for-each.

  4. You're outputting an for each item. Put the outside the xsl:for-each.

Example of changes:

      

To truly get your desired output with a 2.0 processor, I'd also suggest using xsl:output and normalize-space():

             


转载请标明出处:how to make xsl tokenize work
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!