Those below mentioned queries will not work because of structure of xml with 
repetitive elements you have.
<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>


If you are always going to validate the attribute values against 1 or just few 
limited values, then you can have path range indexes enabled on the path based 
on attribute values like the below one

/root/child1/child2[@att=1]/child3[@att=1]

and can run a query like this

cts:search(/root/child1/child2/child3, 
cts:path-range-query('/root/child1/child2[@att=1]/child3[@att=1]', '=', ''))


This will return you

<child3 att="1" id="1"/>

But if the attribute values can be too variant, then having those many path 
range indexes may not be a viable solution.

The other best solution is

cts:search(/root/child1/child2, 
cts:element-attribute-value-query(xs:QName('child2'), xs:QName('att'), 
"1"))/child3[@att=1]

With the structure of xml, it is not possible to use element-attribute-value 
queries on both child2 and child3.




Thanks,
Sudheer

From: [email protected] 
[mailto:[email protected]] On Behalf Of Danny Sinang
Sent: Friday, July 10, 2015 6:00 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Equivalent conversion from Xquery to 
cts:queries

If that doesn't work, try this :

cts:search(collection()/root/child1,
  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:59 AM, Danny Sinang 
<[email protected]<mailto:[email protected]>> wrote:
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]<mailto:[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]<mailto:[email protected]>>

>Subject: [MarkLogic Dev General] Equivalent conversion from Xquery to

>       cts:queries

>To: [email protected]<mailto:[email protected]>

>Message-ID: 
><[email protected]<mailto:[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]<mailto:[email protected]>>

>Subject: Re: [MarkLogic Dev General] Equivalent conversion from Xquery

>       to      cts:queries

>To: <[email protected]<mailto:[email protected]>>

>Message-ID:

>       
> <[email protected]<mailto:[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]>
> 
>[mailto:[email protected]<mailto:[email protected]>]
> On Behalf Of ???

>Sent: Friday, July 10, 2015 1:40 PM

>To: [email protected]<mailto:[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]<mailto:[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]<mailto:[email protected]>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general




---
This communication may contain confidential and/or privileged information. If 
you are not the intended recipient (or have received this communication in 
error) please notify the sender immediately and destroy this communication. Any 
unauthorized copying, disclosure or distribution of the material in this 
communication is strictly forbidden.

Deutsche Bank does not render legal or tax advice, and the information 
contained in this communication should not be regarded as such.
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to