This works just fine for me:

let $xml := document{
<catalog>
        <product dept="WMN">
                <number>557</number>
                <name language="en">Fleece Pullover</name>
                <colorChoices>navy black</colorChoices>
        </product>
        <product dept="ACC">
                <number>563</number>
                <name language="en">Floppy Sun Hat</name>
        </product>
        <product dept="ACC">
                <number>443</number>
                <name language="en">Deluxe Travel Bag</name>
        </product>
        <product dept="MEN">
                <number>784</number>
                <name language="en">Cotton Dress Shirt</name>
                <colorChoices>white gray</colorChoices>
                <desc>Our <i>favorite</i> shirt!</desc>
        </product>
</catalog>
}
return (
for $i in $xml/catalog/product
where $i/@dept = 'WMN'
return $i/name,

for $i in $xml/catalog/product/name
where $i/../@dept = 'WMN'
return $i
)

I am getting Fleece Pullover twice..

Cheers,
Geert

From: 张晓博 <[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Date: Monday, June 29, 2015 at 3:25 AM
To: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: [MarkLogic Dev General] Can anyone tell me why the result of the 
second xqery is empy?

There is one XML document stored in my database, the content of the XML 
document is:
<catalog>
        <product dept="WMN">
                <number>557</number>
                <name language="en">Fleece Pullover</name>
                <colorChoices>navy black</colorChoices>
        </product>
        <product dept="ACC">
                <number>563</number>
                <name language="en">Floppy Sun Hat</name>
        </product>
        <product dept="ACC">
                <number>443</number>
                <name language="en">Deluxe Travel Bag</name>
        </product>
        <product dept="MEN">
                <number>784</number>
                <name language="en">Cotton Dress Shirt</name>
                <colorChoices>white gray</colorChoices>
                <desc>Our <i>favorite</i> shirt!</desc>
        </product>
</catalog>

when i execute the follow xquery :
for $i in collection('http://marklogic.com/xdmp/test')/catalog/product
where $i/@dept = 'WMN'
return $i/name;
the result is:
<namelanguage="en">
Fleece Pullover
</name>
But, if i use the follow xquery to do the same thing, the result will be empty

for $i in collection('http://marklogic.com/xdmp/test')/catalog/product/name
where $i/../@dept = 'WMN'
return $i;

Can anyone tell me why the result of second xqery is empy?


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

Reply via email to