Let’s say I have a line in an XML file like the following (derived from an HTML file):
<i>This is a nice poem<br/>It doesn't rhyme<br/>because right now<br/>I don't have time</i>
I am attempting to right an XSLT to split this string with the following output:
<stanza>
<line>This is a nice poem</line>
<line>It doesn't rhyme</line>
<line>because right now</line>
<line>I don't have time</line>
</stanza>
I have found numerous examples on how to split this if it were delimited with some sort of text, but because it it delimited with an actual element tag, I am really getting stuck. Anyone have any thoughts?
There is no need to split. You have a series of nodes that are children of
<i>, some of them (the text nodes) you are interested in, some of them not (the<br>nodes).The
<br>nodes do not appear in the output because you do not handle them – you are applying templates to the text nodes only (note thattext()selects text nodes).The
<br>still fulfill an important function – they are the ones that delimit your text nodes, effectively doing the “split” for you.