If you are using XML/XSLT to display a list of pages, and that list contains some HTML from within the page, it is sometimes good to remove the HTML markup from the text so that it displays correctly in the list.
The following XSL template shows how to remove the tags from the HTML so that you are only left with the text within the HTML.
<xsl:template name="removeHtmlTags"> <xsl:param name="html"/> <xsl:choose> <xsl:when test="contains($html, '<')"> <xsl:value-of select="substring-before($html, '<')"/> <!-- Recurse through HTML --> <xsl:call-template name="removeHtmlTags"> <xsl:with-param name="html" select="substring-after($html, '>')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$html"/> </xsl:otherwise> </xsl:choose> </xsl:template>
To use the template you call it passing the HTML as a paramter...
<xsl:variable name="pureText"> <xsl:call-template name="removeHtmlTags"> <xsl:with-param name="html" select="Body" /> </xsl:call-template> </xsl:variable> <div class="blogText"> <xsl:value-of select="substring($pureText, 0, 250)" />...<br/> </div>
This shows setting a variable called pureText and setting it to the result of calling the template removeHtmlTags. Finally it writes out the resultant text within a <DIV> tag.