|
[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 valuesSteve Taylor sstaylo at comcast.netFri May 9 17:36:00 PDT 2008
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://x-query.com/pipermail/talk/attachments/20080509/4c02332a/attachment.htm
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Cast Your Vote
We need your help – Vote for DataDirect XML Products!
Winners and finalists announced at SOA World Conference in November. Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|







