« XSLT to remove the first word of the string | Home | XSLT to trim the string to the last character »

XSLT to strip HTML

<!--
strip_HTML
removes all HTML from a given value (including tags that may be left open-ended when returned by the db)
-->

<xsl:template name="strip_HTML">
<xsl:param name="value"/>
<xsl:choose>
<xsl:when test="contains($value,'&lt;')">
<xsl:value-of select="substring-before($value,'&lt;')" disable-output-escaping="yes"/>
<xsl:choose>
<xsl:when test="contains(substring-after($value,'&lt;'),'&gt;')">
<xsl:call-template name="strip_HTML">
<xsl:with-param name="value"><xsl:value-of select="substring-after($value,'&gt;')"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>

</xsl:template>

Topics: XSLT, html | Submitter: admin

Comments

You must be logged in to post a comment.

Keep on coding