XSLT template to convert line breaks to bullets
This is an open discussion with 5 replies, filed under XSLT.
Search
I used the string repace utility a couple of times.
You could replace <br /> with <br /> •
Search for: <br />
and replace with: <br /> •
And you could ad a bullet before the string
Alternatively, you could use the string:split
function by Zimmen:
<xsl:copy-of select="string:split('item1#item2#item3','#','ul','li')" />
Usually, manually inserting a bullet before the string is not a semantic solution, that's why I would suggest the "split" approach.
If you go for the string replace a true list would be better indeed,
Search for <br />
and replace with </li><li>
And wrap the string in <ul> <li> string </li> </ul>
Thanks guys. I used the string:split function as @eKoeS suggested. The usage (where the node name is Features__c) was:
<xsl:copy-of select="string:split(Features__c,' ','ul','li')" />
Hmm... Have you tried the following yet?
<ul> <xsl:for-each select="element/text()"> <li> <value-of select="." /> </li> </xsl:for-each> </ul>
It will iterate over all text elements, separated by any kind of node.
Create an account or sign in to comment.
I'm looking for a template which takes a string and converts it to a bulleted list. So it would need to add a
<ul>
and<li>
tag to the start of the string, add</li><li>
after each line break and then close the tags at the end.I tried to amend the nl2br template but Symphony doesn't like me using
</li><li>
. I just get scolded for "Opening and ending tag mismatch".Can anyone suggest a beautiful XSLT solution?
Thanks
S