我希望将身份转换修改为跳过元素,其中任何属性为空,例如:
复制<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>
,但这只删除了空属性,仍然复制了元素。
答案 0 :(得分:0)
使用<xsl:template match="*[@*[. = '']]"/>
删除这些元素,或使用<xsl:template match="*[@*[. = '']]"><xsl:apply-templates></xsl:template>
仅处理其内容。当然,这些模板与身份转换模板一起使用。