Hi Jacob,
Your query will not work with an element-query constructor. The
element-query constructor searches through all text-node descendants of
the specified element; it does not search through attribute nodes.
Using the first parameter to cts:search, you can test for both the
attribute and the element value you want.
The two methods I suggested earlier should work, I think. For example:
cts:search(/mydoc/data/carList/car,
cts:and-query((
cts:element-value-query(xs:QName("car"), "m3"),
cts:element-attribute-value-query(xs:QName("car"),xs:QName("color"),
"blue")
))
)
This does not return the node (because it is searching under the car
element).
This was does return the node:
cts:search(/mydoc/data/carList/car,
cts:and-query((
cts:element-value-query(xs:QName("car"), "m3"),
cts:element-attribute-value-query(xs:QName("car"),xs:QName("color"),
"green")
))
)
If you want to get the whole document, you can then use XPath or a
function to get there, as follows:
cts:search(/mydoc/data/carList/car,
cts:and-query((
cts:element-value-query(xs:QName("car"), "m3"),
cts:element-attribute-value-query(xs:QName("car"),xs:QName("color"),
"green")
))
)/fn:root()
Does this get you what you need?
-Danny
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jacob
Meushaw
Sent: Monday, December 10, 2007 8:06 AM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] simple cts:search question
I think my example wasn't sufficient to explain the problem fully.
Below is some code that does a better job of showing what I'm doing
and what my problem is.
(: create a test document :)
let $testDoc :=
<mydoc>
<properties>
<docname>cars</docname>
</properties>
<data>
<carList>
<car color="green">M3</car>
<car color="blue">beetle</car>
<car color="yellow">fiat</car>
<car color="red">911</car>
</carList>
</data>
</mydoc>
return xdmp:document-insert("mytest.xml",$testDoc,(),("test"))
(: cts search for docs with a docname of "cars" and containing a blue
M3 in it's car list :)
(: This query returns the document because there is a car with a color
of blue and a car with a name of M3. :)
(: This is not the behavior I'm looking for. I want it to fail because
the M3 is not blue. :)
let $query := cts:and-query((
cts:element-query(xs:QName("properties"),cts:element-value-query(xs:QNam
e("docname"),"cars")),
cts:element-query(xs:QName("carList"),
cts:and-query((
cts:element-attribute-value-query(xs:QName("car"),QName("","color"),"blu
e"),
cts:element-value-query(xs:QName("car"),"M3")
))
)
))
return cts:search(collection("test")/mydoc,$query)
On Dec 6, 2007 1:01 PM, Danny Sokolsky <[EMAIL PROTECTED]> wrote:
> Thanks Mike, you are absolutely correct. Sorry 'bout that...
>
> So here are a few ways you might do this:
>
> 1) with XPath and cts:contains
>
> //car[cts:contains(., cts:and-query((
> cts:element-value-query(xs:QName("car"), "m3"),
> cts:element-attribute-value-query(xs:QName("car"),
> xs:QName("color"),
> "green"))))]
>
> 2) with cts:search
>
> cts:search(/carList/car,
> cts:and-query((
> cts:element-value-query(xs:QName("car"), "m3"),
>
cts:element-attribute-value-query(xs:QName("car"),xs:QName("color"),
> "green")
> ))
> )
>
> Does that get you what you are looking for?
>
> -Danny
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
>
> [mailto:[EMAIL PROTECTED] On Behalf Of Mike
> Sokolov
> Sent: Thursday, December 06, 2007 9:42 AM
> To: General Mark Logic Developer Discussion
> Subject: Re: [MarkLogic Dev General] simple cts:search question
>
> There might be something about the scope of the query (first arg to
> cts:search), but in my experience cts:element-query doesn't include
> itself in its scope, only its descendants, so I don't think the change
> you are suggesting will solve his problem? I put in a change request
to
>
> correct that: it seems like the behavior everyone expects.
>
> -Mike
>
> Danny Sokolsky wrote:
> > I think the problem is that the cts:element-query is on the
"carList"
> > element, and it should be on the "car" element.
> >
> > -Danny
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Jacob
> > Meushaw
> > Sent: Thursday, December 06, 2007 8:58 AM
> > To: [email protected]
> > Subject: [MarkLogic Dev General] simple cts:search question
> >
> > Hello All,
> >
> > I'm stumped on what must be a very simple cts:search question.
> >
> > I'm trying to identify documents in my database using cts:search
which
> > match a set of parameters. The case I'm stumped on is where I want
to
> > match on both the value of the element as well as one of it's
> > attributes.
> >
> > For example a document might contain:
> >
> > <carList>
> > <car color="green">M3</car>
> > <car color="blue">beetle</car>
> > <car color="yellow">fiat</car>
> > <car color="red">911</car>
> > </carList>
> >
> > I can't seem to figure out how to construct a cts query that matches
> > both the attribute value and the element value of the same element:
> >
> > cts:element-query(
> > xs:QName("carList"),
> > cts:and-query((
> >
> >
>
cts:element-attribute-value-query(xs:QName("car"),QName("","color"),"blu
> > e"),
> > cts:element-value-query(xs:QName("car"),"M3")
> > ))
> > )
> >
> > This incorrectly matches the example. The M3 is not blue.
> >
> > Hopefully this makes sense.
> >
> > Any ideas?
> >
> > Thanks,
> > Jake
> > _______________________________________________
> > General mailing list
> > [email protected]
> > http://xqzone.com/mailman/listinfo/general
> > _______________________________________________
> > General mailing list
> > [email protected]
> > http://xqzone.com/mailman/listinfo/general
> >
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
>
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general