假设我有一个非常简单的XML,带有空标记'B':
<Root>
<A>foo</A>
<B></B>
<C>bar</C>
</Root>
Run Code Online (Sandbox Code Playgroud)
我目前正在使用XSLT删除一些标签,例如'C':
<?xml version="1.0" ?>
<xsl:stylesheet version="2.0" xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" encoding="utf-8" omit-xml-declaration="yes" />
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="C" />
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
到目前为止还好,但问题是我最终得到这样的输出:
<Root>
<A>foo</A>
<B/>
</Root>
Run Code Online (Sandbox Code Playgroud)
当我真正想要的时候:
<Root>
<A>foo</A>
<B></B>
</Root>
Run Code Online (Sandbox Code Playgroud)
有没有办法阻止'B'崩溃?
谢谢.
归档时间: |
|
查看次数: |
6839 次 |
最近记录: |