Hi,

I'm trying to specified a result root node for my query in a customizable 
context.

Take this documents for instance ("/test/doc1.xml") :

<?xml version="1.0" encoding="UTF-8"?>
<doc docId="1" xmlns="sto:test">
    <title>foobar</title>
    <authors>
        <author>
            <firstname>stephane</firstname>
            <lastname>toussaint</lastname>
        </author>
        <author>
            <firstname>my</firstname>
            <lastname>self</lastname>
        </author>
    </authors>
</doc>   

I'd like to retrieve for instance doc which contains title "foobar". Easy 
enough the query will be :

cts:search(
  xdmp:directory("/test/"),
  cts:element-value-query(fn:QName("sto:test", "title"), "foobar")
)

Now if I want to retrieve docs written by toussaint.

cts:search(
  xdmp:directory("/test/"),
  cts:element-value-query(fn:QName("sto:test", "lastname"), "toussaint")
)

Ok, so far so good. Now I want to change the root of the element to return. I'd 
like to return authors instead of the doc directly.
Retrieving the authors of a particular doc is easy :

cts:search(
  xdmp:directory("/test/"),
  cts:element-value-query(fn:QName("sto:test", "title"), "foobar")
)//*:author

But now if I want only authors with 'toussaint' has lastname

cts:search(
  xdmp:directory("/test/"),
  cts:element-value-query(fn:QName("sto:test", "lastname"), "toussaint")
)//*:author

This query doesn't work because it return every authors for the document with 
an author named toussaint (return 2 results instead of one).

The thing is to change the root node of the search query :

cts:search(
  xdmp:directory("/test/")//*:author,
  cts:element-value-query(fn:QName("sto:test", "lastname"), "toussaint")
)

But how could I combined for instance title with lastname and return only the 
author ?

cts:search(
  xdmp:directory("/test/")//*:author,
  cts:and-query((
    cts:element-value-query(fn:QName("sto:test", "title"), "foobar"),
    cts:element-value-query(fn:QName("sto:test", "lastname"), "toussaint")
  ))
)

This return nothing because there is no 'title' element under 'author'

cts:search(
  xdmp:directory("/test/"),
  cts:and-query((
    cts:element-value-query(fn:QName("sto:test", "title"), "foobar"),
    cts:element-value-query(fn:QName("sto:test", "lastname"), "toussaint")
  ))
)//*:author

This returns 2 authors instead of only the matching one.

So briefly the question is,  whatever the constraint part of my query I want to 
be able to retrieve the closet element of the root element I choose to return 
(I hope I'm clear enough).
Is there something that can be done with the cts api ?

Thanks,

Stéphane


_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to