我想要一种从 XHTML 文档中去除标签的简单而简单的方法,并且相信在所有选项中必须有一些足够简单的东西,例如:XSLT、XPath、XQuery、使用 .NET XML 命名空间的自定义 C# 编程。我对别人开放。
For example, I want to strip all
<b>
tags from an XHTML document but keep their inner content and child tags (i.e. not simply skip the bold tag and its children).
我需要维护原始文档的结构减去剥离的标签。
想法:
请您参考如下方法:
I need to maintain the structure of the original document minus the stripped tags
你想过 XSLT 吗?这是专门为转换 XML 和一般树结构而设计的语言。
本次改造 :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="b">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
当应用于任何 XHTML 文档时,如 下面的一个:
<html>
<head/>
<body>
<p> Hello, <b>World</b>!</p>
</body>
</html>
产生想要的正确结果 , 在这种情况下:
<html>
<head/>
<body>
<p> Hello, World!</p>
</body>
</html>