【发布时间】:2016-08-25 14:58:58
【问题描述】:
我希望修改身份转换以跳过任何属性为空的元素,例如:
复制<anyElement anyAttr1="a" anyAttr2="b"/>
但不要复制<anotherElement anotherAttr1="a" anotherAttr2=""/>
注意事项:
元素是否有子元素并不重要。
应该复制完全没有属性的元素(容器元素)
源示例 XML:
<?xml version="1.0" encoding="utf-8"?>
<Parameterset>
<Type Code=""/>
<Inventory Code="250" Index="0"/>
<Inventory Code="350" Index=""/>
</Parameterset>
转换后的示例 XML:
<?xml version="1.0" encoding="utf-8"?>
<Parameterset>
<Inventory Code="250" Index="0"/>
</Parameterset>
我能想到的只有:
<xsl:template match="node()|@*[. != '']">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
,但这只会删除空属性并仍然复制元素。
【问题讨论】: