如何为具有特殊属性值的元素获取 cts:values

How can I get cts:values for elements with special attribute value

我有一个文件

    <document>
     <category selected="true">a</category>
     <category>b</category>
     <category selected="true">c</category>
    </document>

如何只从类别[@selected eq 'true'] 中获取值? 我正在尝试使用下一个:

    cts:element-values(xs:QName("category"), (), (), cts:element-attribute-value-query(xs:QName("category"), xs:QName("selected"), "true"))

但我知道在这种情况下我将获得所有类别。

您的 cts:element-attribute-value-query() 正在匹配具有 category 元素且 selected 属性为 true 的所有文档。然后你的 cts:element-values() returns 每个文档中 category 元素的 all 的不同值,无论类别是否有 @selected = 'true' 属性。

您可能想从许多(也许是数亿)结构相似的文档中获取值,而不仅仅是这个文档。对于一个文档,XPath 就可以了。然而,在整个数据库中,您需要一个范围索引来高效地执行此操作。范围索引,顾名思义,在内存中保存一组有序的值和对文档的引用。这使得跨值范围获取不同的值或计算非常有效。

通过范围索引,您可以使用 cts:values() to get values straight out of the indexes without having to read the documents themselves. Given your document structure, you’ll need a path range index 将选定的类别与未选定的类别区分开来。因此,您将在 category[@selected = 'true'] 上创建一个路径范围索引,然后调用 cts:values(cts:path-reference("category[@selected = 'true']"))cts:values() 也可以将 cts:query 作为其第四个参数来限制匹配值的文档域。