如何在XSLT之后保留空XML标记 - 防止将它们从< B>< / B>中折叠出来到< B /> [英] How to preserve Empty XML Tags after XSLT - prevent collapsing them from <B></B> to <B/>
本文介绍了如何在XSLT之后保留空XML标记 - 防止将它们从< B>< / B>中折叠出来到< B />的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个非常简单的XML,其空标记为B:
Say I have a very simple XML with an empty tag 'B':
<Root>
<A>foo</A>
<B></B>
<C>bar</C>
</Root>
我目前正在使用XSLT删除一些标签,比如'C':
I'm currently using XSLT to remove a few tags, like 'C' for example:
<?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>
到目前为止确定,但问题是我最终得到这样的输出:
So far OK, but the problem is I end up having an output like this:
<Root>
<A>foo</A>
<B/>
</Root>
当我真正想要的时候:
<Root>
<A>foo</A>
<B></B>
</Root>
有没有办法防止'B'崩溃?
Is there a way to prevent 'B' from collapsing?
谢谢。
推荐答案
好的,所以这里对我有用:
Ok, so here what worked for me:
<xsl:output method="html">
这篇关于如何在XSLT之后保留空XML标记 - 防止将它们从< B>< / B>中折叠出来到< B />的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文