How do you split a string based on some separator?
Given a string Topic1,Topic2,Topic3
, I want to split the string based on ,
to generate:
Topic1 Topic2 Topic3
How do you split a string based on some separator?
Given a string Topic1,Topic2,Topic3
, I want to split the string based on ,
to generate:
Topic1 Topic2 Topic3
In XSLT 1.0 you have to built a recursive template. This stylesheet:
Input:
Output:
In XSLT 2.0 you have the
tokenize()
core function. So, this stylesheet:Result:
Thank you user357812. I use your nice template with little customization to make it generic :
Use
fn:tokenize
Depending on what XSL processor you are using, you may have access to the extension function str:tokenize().
So to split
Topic1,Topic2,Topic3
on,
do;which will give the result;
There is no
split
function, but you can use a recursive template withsubstring-before
andsubstring-after
to write your own.See this article for details.
XSLT 1.0
I needed a slight variant compared to other answers given here.
Input:
Ouput:
Input:
Output
If the delimiter is space instead of comma, it would still work.
Input:
Ouput:
I have just created a slightly modified template.
The template can be called as below when the delimiter is comma
The template can be called as below when the delimiter is space