18 Mar

How to remove all HTML tags from a string using XSLT?

This is something a SharePoint programmer usually faces. I hope following solution give you help to move ahead.

 

Removing all HTML tags from a string

<xsl:template name="removeHtmlTags">
<xsl:param name="html"/>
<xsl:choose>
    <xsl:when test="contains($html, ‘&lt;’)">
        <xsl:value-of select="substring-before($html, ‘&lt;’)"/>
        <!– Recurse through HTML –>
        <xsl:call-template name="removeHtmlTags">
        <xsl:with-param name="html" select="substring-after($html, ‘&gt;’)"/>
        </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="$html"/>
    </xsl:otherwise>
</xsl:choose>
</xsl:template>

 

Thanks.

Comments are closed.