I have a macro called 'TextToList' which has a parameter 'Text'. The parameter is filled with the contents of a Multiline Textbox.
In the macro/xsl i want to split the Text on 'new-lines' ('\n' of '\r' ???) Then in a loop i want to create a html list (<ul><li>foo</li><li>bar</li></ul>) with the individual lines.
String to List
Guys,
I have a macro called 'TextToList' which has a parameter 'Text'.
The parameter is filled with the contents of a Multiline Textbox.
In the macro/xsl i want to split the Text on 'new-lines' ('\n' of '\r' ???)
Then in a loop i want to create a html list (<ul><li>foo</li><li>bar</li></ul>) with the individual lines.
I found already something like this:
<xsl:variable name="newlist" select="concat(normalize-space($textToList), '\r')" />
<xsl:variable name="first" select="substring-before($newlist, '\r')" />
<xsl:variable name="remaining" select="substring-after($newlist, '\r')" />
<id>
<li><xsl:value-of select="$first" /></li>
</id>
<xsl:if test="$remaining">
<xsl:call-template name="default">
<xsl:with-param name="list" select="$remaining" />
</xsl:call-template>
</xsl:if>
But i can't make it work.
Can someone help me with this?
Hi,
The best method to use is probably umbraco.library:Split
Something like:
Probably best done with templates but this is just a quick/dirty example :)
Also, if you find \n doesn't work, I've personally had better luck with '
', guess it depends on other factors though.
-Tom
Tom,
thanks for your reply. It didn't work with '\r', '\n', and 
 and 
but i solved the problem: Instead of a textarea i used the tags type and a little XSLT.
<xsl:variable name="newlist" select="normalize-space($textToList)" /> <!-- assuming $textToList already contains the macro parameter?, and that assumption is right! ;-) -->
<xsl:variable name="listSplit" select="umbraco.library:Split($newlist, ',') " />
<ul>
<xsl:for-each select="$listSplit/value">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
is working on a reply...