Search

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

I used the string repace utility a couple of times.
You could replace <br /> with <br /> •
Search for: &lt;br /&gt;
and replace with: &lt;br /&gt; •

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,'&#10;','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.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details