我正在使用xsl脚本从xml的所有部分删除注释.它实际上删除了父节点中的注释,但没有删除其他内部节点中的注释.
[编辑]
更新问题.我的要求是从整个XML文档中删除所有注释.
这种转变:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="comment()"/>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
当应用于任何包含注释节点的XML文档时,如下所示:
<!-- foo -->
<a>
<!-- bar -->
<b>
<c><!-- baz --></c>
</b>
</a>
Run Code Online (Sandbox Code Playgroud)
产生想要的结果(剥离注释节点的同一文档):
<a>
<b>
<c/>
</b>
</a>
Run Code Online (Sandbox Code Playgroud)
请注意:使用最基本和最强大的XSLT设计模式 - 使用和覆盖身份规则.
| 归档时间: |
|
| 查看次数: |
2503 次 |
| 最近记录: |