Wrox Programmer Forums
|
BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2
This is the forum to discuss the Wrox book Beginning XML, 4th Edition by David Hunter, Jeff Rafter, Joe Fawcett, Eric van der Vlist, Danny Ayers, Jon Duckett, Andrew Watt, Linda McKinnon; ISBN: 9780470114872
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2010, 04:50 PM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default Problem with XQuery

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Replace Xquery dved XML 1 June 8th, 2009 12:37 PM
XQuery from command line Tomi XSLT 2 January 16th, 2008 01:58 PM
security on Xquery Tomi XSLT 3 May 7th, 2007 07:34 AM
How to get a XQuery.msi ? goldensaying XML 1 December 13th, 2006 01:01 PM
XQuery sonicDace XML 2 March 19th, 2004 05:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.