我想从 XSLT 3 和 Saxon HE 10.6 的响应中过滤 XML 元素
<!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE -->
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>10.6</version>
</dependency>
我在https://xsltfiddle.liberty-development.net/3MP42Pc和https://xsltfiddle.liberty-development.net/3MP42Pc/1上保存了案例
我希望能够使用
<xsl:mode on-no-match="shallow-skip" />
(即:跳过与过滤器不匹配的元素。)
所以我想复制所有匹配一些更深的属性值的元素
该结构就像带有状态的鞋子数据集,看起来像账单上的通用项目。
账单.xml
<bill>
<item>
<shoes>
<status>0</status>
</shoes>
</item>
<item>
<shoes>
<status>1</status>
</shoes>
</item>
<item>
<shoes>
<status>2</status>
</shoes>
</item>
</bill>
我想要 status=0 的通用物品(任何种类(鞋子))
(否则说:跳过 '*/[status=0'] 不匹配的项目)
票据.xslt
<xsl:stylesheet version="3.0">
<xsl:mode on-no-match="shallow-skip" />
<xsl:template match="item/*[status=0]"/>
</xsl:stylesheet>
结果必须是
<bill>
<item>
<shoes><status>0</status></shoes>
</item>
</bill>
唉,这个脚本什么也没找到
但。如果是
<xsl:mode on-no-match="shallow-copy" />
它找到(如预期的那样)所有不是 status=0 的项目
<bill>
<item/>
<item>
<shoes><status>1</status></shoes>
</item>
<item>
<shoes><status>2</status></shoes>
</item>
</bill>
如果我使用
<xsl:mode on-no-match="deep-copy" />
它找到所有项目(无过滤)。
对我来说这似乎不太合乎逻辑,即使 item 元素具有上下文。
我使用 SAXON HE 版本 10.6,与 javax.xml.transform 的代码的唯一区别是使用
TransformerFactory factory = new **BasicTransformerFactory**();
问题是如何制作一个优雅的小脚本来执行此操作:输出整个 xml,跳过不匹配的项目。