Split pipe separated string width XSLT ,..
April 24, 2009 Leave a comment
Split pipe separated
string width XSL ,..
Ohh,. Boy that’s
the thing ,.. XSL does not include any method for this kind string operation ,..
So how would you solve getting items from a pipe separated string in sitecore,..
a pipe separated string looks something like this ,.. {Q2DCC7A2-DBB3-4A5F-BA84-56DL63C1C77F}|{DA493AD7-FD18-41AC-B14C-419D15AD101A}
so this is what I did and it works, I made a recursive iterator for this string.
<xsl:template name="split">
<xsl:param name="list" />
<xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" />
<xsl:variable name="first" select="substring-before($newlist, '|')" />
<xsl:variable name="remaining" select="substring-after($newlist, '|')" />
<xsl:if test="$first = ''">
<xsl:value-of select="$newlist" /> Do your stuff …
</xsl:if>
<xsl:if test="$first != ''">
<xsl:value-of select="$first" /> Do your stuff …
</xsl:if>
<xsl:if test="$remaining">
<xsl:call-template name="split">
<xsl:with-param name="list" select="$remaining" />
</xsl:call-template>
</xsl:if>
</xsl:template>
Get your list and
you are done ,..
<xsl:call-template
name="split">
<xsl:with-param name="list" select="$LatestGUIDs"></xsl:with-param>
</xsl:call-template>
So this is the funny
part ,.. all of this can be done in a matter og seconds by using sc:Split(string,
XPathNodeIterator) , where string is a field name(which holds the pipe separated
string) and XPathNodeIterator is your node ,..
<xsl:for-each
select="sc:Split(‘field name ',.)">
Do your stuff…
</xsl:for-each>