[MarkLogic Dev General] element queries

Mike Sokolov sokolov at ifactory.com
Thu May 22 14:00:43 PDT 2008


That won't even do what you want, I don't think.

Try this mysterious exercise:

xdmp:document-insert ("/a",
<a type="one">
  matching text
</a>);

cts:search (//a, cts:element-query(xs:QName("a"),
         cts:and-query((
                        cts:element-attribute-value-query(xs:QName("a"), 
xs:QName("type"), "one"),
                        "matching text" )) )

=> get empty result set

I have had a request in for a while to allow cts:element-query to 
include its own attributes, but at the moment at least, it doesn't.

You might find this good enough:
cts:and-query((
                       cts:element-attribute-value-query(xs:QName("a"), 
xs:QName("type"), "one"),
                        "matching text" ))

although the semantics are not the same as:

//a[@type="one"][contains(., "matching text")]

because the matching text could appear in some outer a node as in:

<a type="two"> matching text
<a type="one">
  no match
</a></a>


You might want to fiddle around with fields: if you can burn in the 
attribute value constraint by defining an index I think there is a way 
to to this using a field.

-Mike


Shannon Scott Shiflett wrote:
> hi hi,
>
> is the only way to do a cts:element-query() on elements by name with 
> attribute by name with "text content equal to given phrase" by 
> wrapping a cts:element-query() and a 
> cts:element-attribute-value-query() in a cts:and-query()?  wondering 
> if there is a way requiring fewer lines of xquery.
>
> thank you,
> shannon
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general


More information about the General mailing list