Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking presence of attribute with cts:query

Tags:

marklogic

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.

like image 890
callow Avatar asked Jan 29 '14 14:01

callow


2 Answers

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

like image 131
Ankit Bhardwaj Avatar answered Oct 21 '22 17:10

Ankit Bhardwaj


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'), '*'))
like image 37
mblakele Avatar answered Oct 21 '22 18:10

mblakele