0

Is there a way to strip all HTML from XML with XSLT,
like PHP strip_tags() ?

I want to keep the text, but remove all formatting, etc.
This will be taking place before truncating.

   Hey Kurt, <br> I'd like to suggest that we start inventorying a system feature list at a <br> high-level. From there, we would define the requirements of the features. <br> Next, design to the requirements, develop, test, deploy..wash, rinse, and <br> repeat.. <br> I.E. <br> Event Calendar <br> - Requirement No. 1 <br> - Requirement No. 2
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
Kirk Strobeck
  • 17,984
  • 20
  • 75
  • 114
  • You want to remove it from the XSLT or from the XML? – Abe Miessler Aug 12 '11 at 16:17
  • 1
    Is the HTML escaped within the XML with < and > or does it contain < and > signs? Can we get a example of the XML? – Danny Aug 12 '11 at 16:48
  • 1
    @Kirk Strobeck, There is no strong reason why the text replacement you need should be done with XSLT (although something like this could be attempted). This is not HTML -- there is no HTML markup -- just *escaped* characters. If this was *unescaped*, real XHTML markup, then the solution in XSLT is both powerful and trivial. – Dimitre Novatchev Aug 13 '11 at 14:48

1 Answers1

1

I found this solution on various places in the internet using Google:

Some examples of my research:
here, here, here

<!-- Calling the template that removes tag -->
<xsl:call-template name="remove-html">
    <xsl:with-param name="text" select="{HtmlBody}"/>
</xsl:call-template>

<!-- This will remove the tag -->
<xsl:template name="remove-html">
    <xsl:param name="text"/>
    <xsl:choose>
        <xsl:when test="contains($text, '&lt;')">
            <xsl:value-of select="substring-before($text, '&lt;')"/>
            <xsl:call-template name="remove-html">
                    <xsl:with-param name="text" select="substring-after($text, '&gt;')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
therealmarv
  • 3,692
  • 4
  • 24
  • 42