复杂的 XSLT 字符串拆分?

Complex XSLT String Split?

如何在 XSLT 中拆分此字符串

cast one : 'T','0','1','2'

cast two: 'T','0','1' 

case three: 'T','0'

i tried substring but the result is wrong 

substring-before(substring-after(String,','),',')

我希望拆分后结果为0

对于 XSLT 1.0,您可以为 ' 字符应用额外的 substring-before()substring-after()

substring-before(substring-after(substring-after("'T','0'", ','), "'"), "'")

对于 XSLT 2.0(及更高版本),还有其他选项。

您可以使用 tokenize() function to split the string by ,, and then select the second item, and then use translate()' 字符翻译成空:

translate(tokenize("'T','0','1','2'", ',')[2], "'", "")

或者代替 translate(),您可以将 replace() 与正则表达式捕获组一起使用,然后 select 单引号内的值:

replace(tokenize("'T','0','1','2'", ',')[2], "'(.*)'", "")