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

How to write this XQuery program?

Mark Volkmann volkmann2 at charter.net
Mon Sep 6 20:07:58 PDT 2004


xquery program
Here's my attempt at it. I tested this with Saxon 8. If there's a better
way, I'd love to see it!

declare variable $c1 { doc("c1.xml")/company/parts/part };
declare variable $c2 { doc("c2.xml")/company/parts/part };
declare variable $c3 { doc("c3.xml")/company/parts/part };

declare variable $partId { "p2" };

<result> {
  let $parts := $c1[id=$partId] | $c2[id=$partId] | $c3[id=$partId]
  let $bestPrice := min($parts/price)
  let $bestPart := $parts[price/text()=$bestPrice]
  return <part> {
    $bestPart/id,
    $bestPart/price,
    $bestPart/../../name
  } </part>
} </result>

----- Original Message -----
From: "Zhimao Guo" <http://xquery.com/mailman/listinfo/talk>
To: <http://xquery.com/mailman/listinfo/talk>
Sent: Monday, September 06, 2004 8:48 AM
Subject:  How to write this XQuery program?


> Hi, all:
>
> Now I have three XML files, c1.xml, c2.xml, c3.xml.
> Each XML file contains information of one company, and of parts supplied
by it.
> Given a part id, I want to get the company which offered this part with
the lowest price.
> How can I write this XQuery?
>
> -----begin of source data----
> c1.xml:
>  <company>
>   <name>CompanyA</name>
>   <parts>
>    <part>
>     <id>p1</id>
>     <price>100</price>
>    </part>
>    <part>
>     <id>p2</id>
>     <price>101</price>
>    </part>
>   </parts>
>  </company>
> c2.xml:
>  <company>
>   <name>CompanyB</name>
>   <parts>
>    <part>
>     <id>p2</id>
>     <price>105</price>
>    </part>
>    <part>
>     <id>p3</id>
>     <price>106</price>
>    </part>
>   </parts>
>  </company>
> c3.xml:
>  <company>
>   <name>CompanyC</name>
>   <parts>
>    <part>
>     <id>p2</id>
>     <price>100</price>
>    </part>
>    <part>
>     <id>p6</id>
>     <price>106</price>
>    </part>
>   </parts>
>  </company>
> -----end of source data----
>
> -----begin of expected result----
> <result>
>  <part>
>   <id>p2</id>
>   <price>100</price>
>   <company>CompanyC</company>
>  </part>
> </result>
> -----end of expected result----
>
> Who would like to give me a hand? Thanks very much.
>
> best regards,
> -zhimao
> _______________________________________________
> http://xquery.com/mailman/listinfo/talk
> http://xquery.com/mailman/listinfo/talk
>




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-2011 All Rights Reserved.