您能否帮助从创建的输出和变量中设置的输出中删除空节点。我创建了 xslt 如下
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://www.contoso.com"
version="1.0">
<xsl:variable name="books">
<header>
<book author="Michael Howard">Writing Secure Code</book>
<book author="Michael Kay">XSLT Reference</book>
</header>
<item>
<item1>item1</item1>
<item2></item2>//remove this empty tag
<item3></item3>//remove this empty tag
</item>
<summary>
<summary1>
<sum1>SUB1</sum1>
<sum2></sum2> //remove this empty tag
</summary1>
<summary2>Summary2</summary2>
<summary3>Summ3</summary3>
</summary>
</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="$books"/>
<xsl:for-each select="msxsl:node-set($books)/node()">
<xsl:apply-templates/>
<!--select="ms:node-set($completeDocument[1])/node()"/>-->
</xsl:for-each>
</xsl:template>
<xsl:template match= "*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>
</xsl:stylesheet>
产出已产生
<?xml version="1.0" encoding="utf-8"?>Writing Secure CodeXSLT Referenceitem1item2SUB1sub2Summary2Summ3Writing Secure CodeXSLT Referenceitem1item2SUB1sub2Summary2Summ3
预期产出
<header>
<book author="Michael Howard">Writing Secure Code</book>
<book author="Michael Kay">XSLT Reference</book>
</header>
<item>
<item1>item1</item1>
</item>
<summary>
<summary1>
<sum1>SUB1</sum1>
</summary1>
<summary2>Summary2</summary2>
<summary3>Summ3</summary3>
</summary>
预期输出已显示删除空节点。