给定以下( a) XML文件:
<span deltaxml:deltaV2="A!=B">
<deltaxml:attributes deltaxml:deltaV2="A!=B">
<dxa:class deltaxml:deltaV2="A!=B">
<deltaxml:attributeValue deltaxml:deltaV2="B">LoF</deltaxml:attributeValue>
</dxa:class>
</deltaxml:attributes>
Some Text
</span>..。我希望/需要匹配特定跨跨的<span>语句中的<xsl:template match="..">节点。
基本上,我需要匹配上面所示的条件,以便以后选择/使用“一些文本”部分。但是,一旦我匹配了输入xml中的<span>节点,就很容易做到这一点。但到目前为止,我一直在挠头,无法选择节点。
也许任何人都能流利地掌握稍微复杂的匹配语句,并且知道哪一个是正确的。谢谢!
发布于 2017-08-20 14:39:01
您只需创建一个大谓词表达式and'ing和计数属性。不需要直接匹配节点,因为没有元素的属性是不存在的。然而,元素和属性被计算,以确保span/element中不存在更多或更少的元素/属性。文本节点不被处理,只检查Some Text的存在。
因此,下面的复杂表达式与您描述的元素/属性树结构完全匹配:
<xsl:template match="span[
@deltaxml:deltaV2='A!=B' and
count(descendant::*)=3 and
deltaxml:attributes/@deltaxml:deltaV2 and
count(deltaxml:attributes/@*)=1 and
deltaxml:attributes/dxa:class/@deltaxml:deltaV2 and
count(deltaxml:attributes/dxa:class/@*)=1 and
deltaxml:attributes/dxa:class/deltaxml:attributeValue/@deltaxml:deltaV2='B' and
count(deltaxml:attributes/dxa:class/deltaxml:attributeValue/@*)=1 and
deltaxml:attributes/dxa:class/deltaxml:attributeValue/text()='LoF' and
normalize-space(text()[2])='Some Text']">
MATCH!
</xsl:template>不幸的是,在包含子树的变量中比较产生的两个树片段不起作用,因为它没有比较-op (see here)。
https://stackoverflow.com/questions/45781936
复制相似问题