Replace XSLT Template for Sharepoint Designer
December 3rd, 2008 . by <Patrick/>If you need to do a find and replace when outputting a column in a data view you can use the following:
�
<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>
�
Call the template code:
Say you have a column named ColumnName and you want to replace all occurrences of True and set them to False…..
<xsl:call-template name=”stringreplace”>
<xsl:with-param name=”stringvalue” select=”@ColumnName” />
<xsl:with-param name=”from” select=”True” />
<xsl:with-param name=”to” select=”False” />
</xsl:call-template>
�