Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • jwijnker 7 posts 27 karma points
    Mar 23, 2011 @ 12:24
    jwijnker
    0

    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?

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 23, 2011 @ 12:41
    Tom Fulton
    0

    Hi,

    The best method to use is probably umbraco.library:Split

    Something like:

    <xsl:variable name="newlist" select="concat(normalize-space($textToList), '\r')" />  <!-- assuming $textToList already contains the macro parameter? -->
    <xsl:variable name="listSplit" select="umbraco.library:Split($newlist, '\n')" />
    <ul>
    <xsl:for-each select="$listSplit/value">
    <li><xsl:value-of select="." /></li>
    <xsl:for-each>
    </ul>

    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 '&#xa;', guess it depends on other factors though.

    -Tom

  • jwijnker 7 posts 27 karma points
    Mar 23, 2011 @ 14:14
    jwijnker
    0

    Tom,

    thanks for your reply. It didn't work with '\r', '\n', and &#xa; and &#xd;

    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>

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

    Continue discussion

Please Sign in or register to post replies