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

Better way to structure XQuery

Christian Grün christian.gruen at gmail.com
Wed Jul 8 21:04:08 PDT 2009


  Better way to structure XQuery
> The following code is what I have now, and it works. But something tells
> me it can be better. I am using XQuery implementation within the eXist
> database if that helps.
>
> let $mydoc :=doc('http://localhost:8080/exist/rest/db/bio.xml')
> let $profileType := 'Standard'
> let $paths := ($mydoc/metadata/idinfo/spdom/bounding/boundalt/altmin,
> $mydoc/metadata/idinfo/spdom/bounding/boundalt/altmax, path3, path4, ...)
>
> for $p in $paths
>   let $profileType := if ($p) then 'Biological' else $profileType

Stacy,
I don't know if this helps, but you your query could be simplified as follows:

  let $mydoc := doc('http://localhost:8080/exist/rest/db/bio.xml')
  let $profileType :=
    if(
      $mydoc/metadata/idinfo/spdom/bounding/boundalt/altmin,
      $mydoc/metadata/idinfo/spdom/bounding/boundalt/altmax,
      path3, path4, ...
    ) then 'Biological' else 'Standard'
  return
    ...

If one of the paths exists, $profileType will be set to 'Biological'.
- As variables cannot be assigned more than once in XQuery, a second
assignment of $profileType will just hide the first one.

Best,

Christian,
http://basex.org



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.