Comma seperated values Options
rorythecheese
Posted: Thursday, May 15, 2008 5:29:08 PM

Rank: Enthusiast

Joined: 2/15/2008
Posts: 37
Location: London, England
Just wondering what the best way of spliting values seperated by commas is.

For example i have a document type with a checkbox choice which when more than one box is ticked the umbraco.config file

<data alias="list">example1,example2,example4</data>

I want to in my xslt file split these values out and then use them in xsl:if tags.


I found this online - and have used it for separating, but is a bit of an arse and havent figured out how to use the values for xsl:if 's etc....

Code:
<xsl:template match="Record">
      <tr>
          <xsl:call-template name="divide">
              <xsl:with-param name="to-be-divided" select="."/>
              <xsl:with-param name="delimiter" select="','"/>
          </xsl:call-template>
      </tr>
  </xsl:template>
 
  <xsl:template name="divide">
      <xsl:param name="to-be-divided"/>
      <xsl:param name="delimiter"/>
      <xsl:choose>
          <xsl:when test="contains($to-be-divided,$delimiter)">
              <td><xsl:value-of
  select="substring-before($to-be-divided,$delimiter)"/></td>
              <xsl:call-template name="divide">
                  <xsl:with-param name="to-be-divided"
  select="substring-after($to-be-divided,$delimiter)"/>
                  <xsl:with-param name="delimiter" select="','"/>
              </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
              <td><xsl:value-of select="$to-be-divided"/></td>
          </xsl:otherwise>
      </xsl:choose>
</xsl:template>



I checked around a bit more and saw about tokenize then checked on this forum and saw someone use Exslt.ExsltStrings:tokenize but i cant figure out how to get it to work. Am i on the right tracks with this?/

Anyone know the best way to split the value for use?
Dirk
Posted: Thursday, May 15, 2008 6:22:46 PM

Rank: Addict

Joined: 9/27/2007
Posts: 707
Location: Belgium
Found this code:

Code:
<xsl:variable name="mcpNodeSet" select="umbraco.library:Split(data[@alias='mcp'],',')"/>

<xsl:for-each select="$mcpNodeSet/value">
    <xsl:variable name="currentItem" select="umbraco.library:GetXmlNodeById(current()/text())"/>
    <xsl:value-of select="$currentItem/@nodeName"/>
</xsl:for-each>


in this thread as an alternative. Credits go to Casey of course.

Good luck,
/Dirk


level 1 certified - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
rorythecheese
Posted: Friday, May 16, 2008 12:27:06 PM

Rank: Enthusiast

Joined: 2/15/2008
Posts: 37
Location: London, England
Ahh nice one, seems to do the trick.
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.