我想通过xslt创建一个空文件。xslt - 使用xslt创建空文件1.0
输入的样本是:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Businessman>
<siblings>
<sibling>John </sibling>
</siblings>
<child> Pete </child>
<child> Ken </child>
</Businessman>
当输入包含“孩子”标签的任何存在,它应该产生的文件原样。当输入没有任何'child'标签时,我需要创建一个空文件(0字节文件)。
这是我的尝试:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="@*|node()">
<xsl:choose>
<xsl:when test="/Businessman/child">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
这使文件不变的时候有任何存在的“孩子”的标签。但没有“孩子”标签时没有产生任何空文件。
文件我需要测试看起来像:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Businessman>
<siblings>
<sibling>John </sibling>
</siblings>
</Businessman>
任何帮助将是巨大的!
感谢
如何调整xsl:输出?我尝试了一些东西 - 但我不断收到<?xml version =“1.0”encoding =“UTF-8”?>“ –
set'omit-xml-declaration' to'yes' –