【发布时间】:2016-03-23 16:49:20
【问题描述】:
我有以下 CTS 搜索查询:
cts:search(/parent,
cts:and-query((
cts:element-attribute-value-query(xs:QName('parent'), xs:QName('attr'), 'value'),
cts:element-attribute-value-query(xs:QName('child'), xs:QName('attr-1'), 'value-2'),
cts:element-attribute-value-query(xs:QName('child'), xs:QName('attr-2'), 'value-3')
))
)/child[@attr-1 eq 'value-2' and @attr-2 eq "value-3"]
(: Returns /parent/child elements matching criteria :)
我有一些关于父母的限定词,以及关于孩子的限定词。我想要的最终结果只是孩子们。为了做到这一点,正如你从上面看到的,我必须:
- 搜索符合父条件 + 子条件的文档
- 获取该文档后,按与上述相同的条件逻辑过滤掉子项
这行得通,但是我在 cts:query 中必须有与我在 xPath 上为孩子们做的相同的逻辑,这似乎真的很愚蠢。逻辑被不必要地重复。
有没有一种方法可以让我在 cts:query 中完成所有这些操作,而不必像上面的示例那样使用额外的 xPath 表达式?
这和我想要的差不多,但是对cmets中指定的问题不起作用:
cts:search(/parent/child,
cts:and-query((
cts:element-attribute-value-query(xs:QName('parent'), xs:QName('attr'), 'value'), (: The problem is this line... I can't filter by the parent, as it is above the scope of my first parameter (/parent/rule) :)
cts:element-attribute-value-query(xs:QName('child'), xs:QName('attr-1'), 'value-2'),
cts:element-attribute-value-query(xs:QName('child'), xs:QName('attr-2'), 'value-3')
))
)
【问题讨论】: