I want to split an address on semicolons (;
) into rows separated by <br />
:
e.g. if address
=123 Elm Street
, I want to output 123 Elm Street
,
but if address
=123 Elm Street;PO Box 222
, I want to output
123 Elm Street<br />PO Box 222
and if address
=123 Elm Street;PO Box 222;c/o James Jones
, I want to output
123 Elm Street<br />PO Box 222<br />c/o James Jones
Is there a way to do this? (probably easy but I'm not that familiar with XSLT)
The plain XSL selector is
<xsl:value-of select="address"/>
and I would like to modify this XSLT fragment to split on semicolon.
update: Apparently the answer involves the use of <xsl:call-template>
and the functions substring-before()
and substring-after()
.
But I'm a beginner to XSLT and I could really use some help for how to do this.
If your XSLT processor supports EXSLT, you can use str:tokenize, otherwise, the link contains an implementation using functions like substring-before.
I. Plain XSLT 1.0 solution:
This transformation:
when applied on this XML document:
produces the wanted, corrected result:
II. FXSL 1 (for XSLT 1.0):
Here we just use the FXSL template
str-map
(and do not have to write recursive template for the 999th time):when this transformation is applied on any XML document (not used), the same, wanted correct result is produced:
III. Using XSLT 2.0
when this transformation is applied on this XML document:
the wanted, correct result is produced: