This project is read-only.

StringReplace Template

Sep 8, 2010 at 10:49 AM

I found a clever template here: http://vspug.com/mkruger/2007/06/26/free-sharepoint-dataview-tips/

Hope it helps.

Sep 29, 2010 at 9:55 AM

Just to make things a little quicker, here's the template from the referenced page:

<xsl:template name="stringreplace">
            <xsl:param name="stringvalue"/>
            <xsl:param name="from"/>
            <xsl:param name="to"/>
            <xsl:choose>
                <xsl:when test="contains($stringvalue, $from)">
                    <xsl:value-of select="substring-before($stringvalue, $from)"/>
                    <xsl:if test="contains(substring($stringvalue, 1, string-length($stringvalue) - 1), $from)">
                        <xsl:value-of select="$to"/>
                        <xsl:call-template name="stringreplace">
                            <xsl:with-param name="stringvalue" select="substring-after($stringvalue, $from)"/>
                            <xsl:with-param name="from" select="$from"/>
                            <xsl:with-param name="to" select="$to"/>
                        </xsl:call-template>
                    </xsl:if>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$stringvalue"/>
                </xsl:otherwise>
            </xsl:choose>
</xsl:template>

Note that there are other useful things on the page iOnline247 referenced, so be sure to take a look ...
Alex
Coordinator
Oct 1, 2010 at 2:22 AM

Thanks, Alex!

May 13, 2011 at 7:33 PM

I found a slightly different template that performs the same function. Not sure which one is "better" but I thought I'd adapt it using some of the naming conventions you've used already and throw it in here for consideration.

<xsl:template name="StringReplace">
  <xsl:param name="TextData"/>
  <xsl:param name="From"/>
  <xsl:param name="To"/>
  <xsl:choose>
    <xsl:when test="contains($TextData,$From)">
      <xsl:call-template name="StringReplace">
        <xsl:with-param name="TextData" select="concat(substring-before($TextData,$From),$To,substring-after($TextData,$From))"/>
        <xsl:with-param name="From" select="$From"/>
        <xsl:with-param name="To" select="$To"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$TextData"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

May 26, 2011 at 3:00 PM
Edited May 26, 2011 at 3:08 PM

Moved to new thread: http://spxslt.codeplex.com/discussions/259103

Coordinator
May 26, 2011 at 3:05 PM

Eric:

I think yours is a little different. Are you simply removing the separating semicolons? You should be able to do that with MultiSelectDisplay?

M.

May 26, 2011 at 3:07 PM

Put it in a new thread, this is different.  Updating this.