Try something like this :

cts:search(collection()/root/child1/child2,
  cts:and-query((
    cts:element-attribute-value-query(xs:QName("child2"), xs:QName("att"),
"1"),
cts:element-query ( xs:QName("child2"),
    cts:element-attribute-value-query(xs:QName("child3"), xs:QName("att"),
"1")
)
    )))/child3

On Fri, Jul 10, 2015 at 5:04 AM, 张晓博 <[email protected]> wrote:

> query
> cts:search(/root/child1/child2,
>
>  cts:and-query((
>     cts:element-attribute-value-query(xs:QName("child2"), xs:QName("att"), 
> "1"),
>     cts:element-attribute-value-query(xs:QName("child3"), xs:QName("att"), 
> "1")
>    )))/child3[@att = "1"]
> can work, but it is not i want.
>
> I want the query like this:
> cts:search(/root/child1/child2/child3,
>
>  cts:and-query((
>      cts:element-attribute-value-query(xs:QName("child2"), xs:QName("att"), 
> "1"),
>
>     cts:element-attribute-value-query(xs:QName("child3"), xs:QName("att"), 
> "1")
>
> )))
>
> but it can not work  correctly. because cts:element* function can search
> the element and all of child element, but
> if i want to  search its parent element,  is there any cts:queries
> function i can use?
>
>
>
>
>
> >----------------------------------------------------------------------
> >
> >Message: 1
> >Date: Fri, 10 Jul 2015 16:09:37 +0800 (CST)
> >From: ??? <[email protected]>
> >Subject: [MarkLogic Dev General] Equivalent conversion from Xquery to
> >     cts:queries
> >To: [email protected]
> >Message-ID: <[email protected]>
> >Content-Type: text/plain; charset="gbk"
> >
> >In my database, the most of xml documents content likes this:
> ><root>
> ><child1 att="1">
> ><child2 att="1" id="1">
> ><child3 att="1" id="1">
> ></child3>
> ><child3 att="2" id="2">
> ></child3>
> ></child2>
> ><child2 att="1" id="2">
> ><child3 att="3">
> ></child3>
> ></child2>
> ></child1>
> ></root>
> >
> >
> >the Xquery is:
> >for $i in collection()/root/child1/child2/child3
> >where
> >$i/@att = '1'
> >and $i/..[@att] = '1'
> >return $i/@id
> >and its result is:
> ><child3att="1"id="1"> </child3>
> >
> >
> >but when i use the cts:query to do the same thing , the result is different
> >
> >
> >query :
> >cts:search(collection()/root/child1/child2,
> >  cts:and-query((
> >    cts:element-attribute-value-query(xs:QName("child2"), xs:QName("att"), 
> > "1"),
> >    cts:element-attribute-value-query(xs:QName("child3"), xs:QName("att"), 
> > "1")
> >    )))/child3
> >and result is:
> ><child3att="1"id="1"></child3>
> >element
> ><child3att="2"id="2"></child3>
> >
> >
> >so how can i rewrite the XQuery by useing cts:queries when ../ appear in the 
> >where condition?
> >-------------- next part --------------
> >An HTML attachment was scrubbed...
> >URL: 
> >http://developer.marklogic.com/pipermail/general/attachments/20150710/a15af41a/attachment-0001.html
> >
> >------------------------------
> >
> >Message: 2
> >Date: Fri, 10 Jul 2015 08:32:38 +0000
> >From: <[email protected]>
> >Subject: Re: [MarkLogic Dev General] Equivalent conversion from Xquery
> >     to      cts:queries
> >To: <[email protected]>
> >Message-ID:
> >     <[email protected]>
> >Content-Type: text/plain; charset="us-ascii"
> >
> >Hi,
> >
> >Try this ,
> >
> >cts:search(/root/child1/child2,
> >  cts:and-query((
> >    cts:element-attribute-value-query(xs:QName("child2"), xs:QName("att"), 
> > "1"),
> >    cts:element-attribute-value-query(xs:QName("child3"), xs:QName("att"), 
> > "1")
> >    )))/child3[@att = "1"]
> >
> >Thanks and regards
> >Raja >>>
> >
> >From: [email protected] 
> >[mailto:[email protected]] On Behalf Of ???
> >Sent: Friday, July 10, 2015 1:40 PM
> >To: [email protected]
> >Subject: [MarkLogic Dev General] Equivalent conversion from Xquery to 
> >cts:queries
> >
> >In my database, the most of xml documents content likes this:
> ><root>
> >            <child1 att="1">
> >                        <child2 att="1" id="1">
> >                                    <child3 att="1" id="1">
> >                                    </child3>
> >                                    <child3 att="2" id="2">
> >                                    </child3>
> >                        </child2>
> >                        <child2 att="1" id="2">
> >                                    <child3 att="3">
> >                                    </child3>
> >                        </child2>
> >            </child1>
> ></root>
> >
> >the Xquery is:
> >for $i in collection()/root/child1/child2/child3
> >where
> >$i/@att = '1'
> >and $i/..[@att] = '1'
> >return $i/@id
> >and its result is:
> ><child3 att="1" id="1"> </child3>
> >
> >but when i use the cts:query to do the same thing , the result is different
> >
> >query :
> >cts:search(collection()/root/child1/child2,
> >  cts:and-query((
> >    cts:element-attribute-value-query(xs:QName("child2"), xs:QName("att"), 
> > "1"),
> >    cts:element-attribute-value-query(xs:QName("child3"), xs:QName("att"), 
> > "1")
> >    )))/child3
> >and result is:
> ><child3 att="1" id="1"></child3>
> >element <http://172.18.34.28:8000/qconsole/>
> ><child3 att="2" id="2"></child3>
> >
> >so how can i rewrite the XQuery by useing cts:queries when ../ appear in the 
> >where condition?
> >
> >This e-mail and any files transmitted with it are for the sole use of the 
> >intended recipient(s) and may contain confidential and privileged 
> >information. If you are not the intended recipient(s), please reply to the 
> >sender and destroy all copies of the original message. Any unauthorized 
> >review, use, disclosure, dissemination, forwarding, printing or copying of 
> >this email, and/or any action taken in reliance on the contents of this 
> >e-mail is strictly prohibited and may be unlawful. Where permitted by 
> >applicable law, this e-mail and other e-mail communications sent to and from 
> >Cognizant e-mail addresses may be monitored.
> >-------------- next part --------------
> >An HTML attachment was scrubbed...
> >URL: 
> >http://developer.marklogic.com/pipermail/general/attachments/20150710/e93bb167/attachment.html
> >
> >------------------------------
> >
> >_______________________________________________
> >General mailing list
> >[email protected]
> >Manage your subscription at:
> >http://developer.marklogic.com/mailman/listinfo/general
> >
> >
> >End of General Digest, Vol 133, Issue 26
> >****************************************
>
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to