使用XSLT从XML中删除类似HTML的字符(不是标记)?

时间:2011-08-12 16:14:17

标签: xslt

有没有办法用XSLT从XML中删除所有HTML,
像PHP strip_tags()

我想保留文字,但删除所有格式等。
这将在截断之前发生。

   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

1 个答案:

答案 0 :(得分:1)

我使用Google在互联网的各个地方找到了这个解决方案:

我的研究的一些例子:
hereherehere

<!-- 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>