XSL Utility: Strip HTML From A Given Value

From VYRE

Jump to: navigation, search

Sometimes you may need to strip the HTML out of a block of text rather than just escaping the output. The following template does so, based on "<" and then ">" being present.

<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>
Personal tools