Checking presence of attribute with cts:query

▼魔方 西西 提交于 2019-12-08 19:34:02

问题


cts:element-query(xs:QName("elm"),cts:and-query(())) will give all the fragments where the element elm is present.

Similarly if I want all documents where an attribute(say atr) is present under elm what would I have to do?

cts:element-attribute-value-query() requires that I pass a value to match against the attribute value. But I want to check only the existence of the attribute irrespective of what value it contains.


回答1:


You can do it by a simple cts:element-attribute-value-query

cts:element-attribute-value-query(
xs:QName('element'), xs:QName('attribute'), '*'))  

In case you have not set wildcarded search true in database, you also need to provide wildcarded enabled search explicitly in cts:element-attribute-value-query

cts:element-attribute-value-query(
xs:QName('element'), xs:QName('attribute'), '*', ("wildcarded")))  

For more details on this you can check cts:element-attribute-value-query page




回答2:


Try using a wildcard. One difference between elements and attributes is that elements can be empty. Attributes can't, so they should always match a wildcard. You may need to enable some character indexes for optimal performance.

cts:element-attribute-value-query(
  xs:QName('div'), xs:QName('id'), '*'))


来源:https://stackoverflow.com/questions/21434099/checking-presence-of-attribute-with-ctsquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!