I have a 1 time transformation to do to a large XML file.
I have :
[stuff]
<items>string1,string2,string3,string4</items>
[other stuff]
I want to replace it with :
<itemList>
<item>string1</item>
<item>string2</item>
<item>string3</item>
<item>string4</item>
</itemList>
I’m hesitating between using a RegEx or XSL. I’ve been trying to go the regex way :
Search
^.*<items>(.*)</items>
Replace with
<itemList>\1</itemList>
I’m stuck at the “find comma and replace them by something”. I’m not even sure it’s doable…
How could I finish this RegEx? Should I go XSL instead?
I would use XSLT 2.0.
XML Input:
XSLT 2.0:
XML Output:
If you don’t have an XSLT 2.0 processor, I would suggest Saxon.