[MarkLogic Dev General] element queries
Shannon Scott Shiflett
sss4r at virginia.edu
Fri May 23 12:20:32 PDT 2008
Mike, I was referring to the example given in the function
documentation for cts:element-attribute-value-query(), but you are
right, that is not exactly what I was looking for. The solution you
provide is indeed good enough, thanks. I hope your enhancement
request to have cts:element-query include its own attributes is
accepted.
On May 22, 2008, at 5:00 PM, Mike Sokolov wrote:
> 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
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
More information about the General
mailing list