[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

XQuery question about accessing ancestor/parent nodes of return values

Steve Taylor sstaylo at comcast.net
Fri May 9 21:51:01 PDT 2008


  XQuery question about accessing ancestor/parent
	nodes of return values
Shannon,

 

That worked perfectly.  Thanks so much for your help!

 

Regards,

Steve

 

From: Shannon Scott Shiflett [mailto:http://x-query.com/mailman/listinfo/talk] 
Sent: Friday, May 09, 2008 4:57 PM
To: Steve Taylor
Cc: http://x-query.com/mailman/listinfo/talk
Subject: Re:  XQuery question about accessing ancestor/parent
nodes of return values

 

 

I see the highlight :)

 

I think you want to do:

 

for $person in //Company/Person 

where $person/Address/Zipcode = '12345' 

return $person

 

On May 9, 2008, at 4:36 PM, Steve Taylor wrote:





Hello all,

 

I'm new to  XQuery and this XQuery mailing list and  I'm hoping someone can
help me answer a question that has been stumping me.

 

I know how to use XQuery to find nodes that match a certain pattern, but I
need to find a way to pass back the parent nodes of the nodes matching the
pattern.

 

For example , here is a small subset from my test XML document (using
completely made up names and addresses) and following that is my Xquery. I
highlighted the matching node tag for my XQuery for easy identification:

 

 

<?xml version="1.0"?>

<Company>

 

<Person>

<Name>

    <LastName>Smith</LastName>

    <FirstName>Bob</FirstName>

    <MiddleInitial></MiddleInitial>

</Name>

<Address>

    <StreetAddress1>123 Elm St</StreetAddress1>

    <StreetAddress2></StreetAddress2>

    <City>Loganville</City>

    <State>LA</State>

    <Zipcode>12345</Zipcode>

</Address>

</Person>

 

<Person>

<Name>

    <LastName>Jones</LastName>

    <FirstName>Mike</FirstName>

    <MiddleInitial>B</MiddleInitial>

</Name>

<Address>

    <StreetAddress1>456 Maple St</StreetAddress1>

    <StreetAddress2></StreetAddress2>

    <City>Baston</City>

    <State>LA</State>

    <Zipcode>12378</Zipcode>

</Address>

</Person>

 

</Company>

 

 

 

I am trying to search the entire XML document using XQuery to return all
<Person> nodes with a <Zipcode> value of '12345'.  Here is my XQuery command
I created:

 

for $address in //Company/Person/Address

where $address/Zipcode = '12345'

return $address

 

This returns to me the following results:

 

<Address>

    <StreetAddress1>123 Elm St</StreetAddress1>

    <StreetAddress2/>

    <City>Loganville</City>

    <State>LA</State>

    <Zipcode>12345</Zipcode>

</Address>

 

 

The problem with the results above is that I need to return the entire
<Person> (including all sub-nodes) with the matching <Zipcode> string, not
just the person's <Address> node since the <Address> node alone does not
tell me who is the matching person. With the results I got back from the
XQuery above I only get the <Address> node, and I can't seem to figure out
how to return the entire <Person> node. Here is the expected results I was
hoping to receive for this example:

 

<Person>

<Name>

    <LastName>Smith</LastName>

    <FirstName>Bob</FirstName>

    <MiddleInitial></MiddleInitial>

</Name>

<Address>

    <StreetAddress1>123 Elm St</StreetAddress1>

    <StreetAddress2></StreetAddress2>

    <City>Loganville</City>

    <State>LA</State>

    <Zipcode>12345</Zipcode>

</Address>

</Person>

 

Does anybody know if it is possible to get the results I am looking for? If
so, please let me know the proper syntax to use for my XQuery command.  I
have looked everywhere for a solution and I can't seem to find anything.

 

Thank you very much in advance,

Steve Taylor

http://x-query.com/mailman/listinfo/talk

 

 

 

_______________________________________________
http://x-query.com/mailman/listinfo/talk
http://x-query.com/mailman/listinfo/talk

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20080509/07881821/attachment.htm


Purchase Stylus Studio Online Today!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.