Hi All,
I am writing below Xquery to retireive data from XML document given below but its returning duplicate data. I just want one pair of record instead of two pair.
Here is the XQuery :
[code]
<html>
{
for$v in
doc("Hierarchy.xml")/Hierarchy/Branch[@Id="Tree2"]
for$l1 in$v/Node/*
for$x indoc("Hierarchy.xml")/Hierarchy/Branch
for$l2 in$x/Node/*for$z indoc("Hierarchy.xml")/Hierarchy/Branch[@Id=$l2/@Connection]
for$l3 in$z/Node/*
for$y indoc("Hierarchy.xml")/Hierarchy/Branch[@Id=$l3/@Connection]
for$l4 in$y/Node/*[@Connection="SmallPlant1"or@Connection="SmallPlant2" ]
for$p indoc("Hierarchy.xml")/Hierarchy/Branch[@Id=$l4/@Connection]
where$l1/@Connection =$l2/@Connection
return
$p/Name
}
</html>
[code]
XML Document :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Hierarchy>
<Branch Id="Forest">
<Name> Forest </Name>
<Node>
<Leaf Connection="Tree1"/>
</Node>
<Node>
<Leaf Connection="Tree2"/>
</Node>
</Branch>
<Branch Id="Tree1">
<Name> My Tree1 </Name>
</Branch>
<Branch Id="Tree2">
<Name> My Tree2 </Name>
<Node>
<Leaf Connection="BigTree1"/>
</Node>
<Node>
<Leaf Connection="BigTree2"/>
</Node>
<Node>
<Leaf Connection="SmallTree1"/>
</Node>
<Node>
<Leaf Connection="SmallTree2"/>
</Node>
</Branch>
<Branch Id="BigTree1">
<Name> My BigTree1 </Name>
<Node>
<Leaf Connection="SmallTree1"/>
</Node>
<Node>
<Leaf Connection="SmallTree2"/>
</Node>
</Branch>
<Branch Id="BigTree2">
<Name> My BigTree2 </Name>
<Node>
<Leaf Connection="SmallTree1"/>
</Node>
<Node>
<Leaf Connection="SmallTree2"/>
</Node></Branch>
<Branch Id="SmallTree1">
<Name> My SmallTree1 </Name>
<Node>
<Leaf Connection="SmallPlant1"/>
</Node>
</Branch>
<Branch Id="SmallTree2">
<Name> My SmallTree2 </Name>
<Node>
<Leaf Connection="SmallPlant2"/>
</Node>
</Branch>
<Branch Id="SmallPlant1">
<Name> My SmallPlant1 </Name>
</Branch>
<Branch Id="SmallPlant2">
<Name> My SmallPlant2 </Name>
</Branch>
</Hierarchy>
And here is the Output which I am getting :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<Name> My SmallPlant1 </Name>
<Name> My SmallPlant2 </Name>
<Name> My SmallPlant1 </Name>
<Name> My SmallPlant2 </Name>
</html>
I want to retreive only one pair of 'My SmallPlant1' and 'My SmallPlant2'
Please tell me where I am doing wrong.
Any help much appriciated.
Thanks
Nelly