我有一个简单的 xml:
<custom-objects>
<custom-object id="1">
<object-attribute attribute-id="address1">Warndtstr. 33</object-attribute>
<object-attribute attribute-id="branch">01</object-attribute>
<object-attribute attribute-id="catalogid">7991</object-attribute>
<object-attribute attribute-id="exportdate">2015-09-19</object-attribute>
</custom-object>
<custom-object>
...
</custom-object>
</custom-objects>
我试图简单地复制每个<custom-object>
包含子元素的元素,其中@attribute-id
is "exportdate"
并具有特定的文本值。
这是我的 xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="custom-object[object-attribute[@attribute-id='exportdate']='2015-09-19']"/>
</xsl:stylesheet>
当使用 xpath 时匹配有效。 xslt 返回空结果。
“我试图简单地复制包含子元素的每个元素,其中 @attribute-id 是“exportdate”并且具有特定的文本值。”
空模板应该用于删除元素。所以目前,您的 XSL 应该删除custom-object
其中“exportdate”等于“2015-09-19”,并复制其他元素。如果您想要相反的结果,请尝试使用具有相反含义的 XPath,例如:
<xsl:template
match="custom-object[not(object-attribute[@attribute-id='exportdate']='2015-09-19')]"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)