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

Problem in validating XQuery

Michael Kay mike at saxonica.com
Mon Oct 1 00:49:08 PDT 2007


  Problem in validating XQuery
> I have the following query:
> 
> xquery version "1.0";
> 
> declare default element namespace "http://www.example.org/driving";
> 
> declare variable $directionsTag :=
> doc("driving.xml")/drivingreport/directions;
> declare variable $startoutTag := $directionsTag/startout;
> 
> declare variable $driveDirections := $directionsTag/drivedirections/*;
> 
> <straight>
> {
>     for $i in $driveDirections
>     return 
      <route>                             
>        <start>{$startoutTag/on/text()}</start>
>        <dist>{$startoutTag/@distanceMiles}</dist>
>        if(fn:compare($i/text(), 'turnonto')) then 

The problem is a missing "{" before the if (a very common mistake). This
means that the whole expression from here to the "else ()" is interpreted as
literal text, not as an XQuery expression. Usually this results in the
expression being copied as text to the result document, or in references to
undeclared variables, but in your case you included the closing "}", and
this wouldn't be valid in literal text (it has to be escaped as "}}") so the
parser reported the error at this point.

          
>             else if(fn:compare($i/text(), 'becomes')) 

compare() returns -1, 0, or +1, and 0 is treated as false, anything else as
true. So this is an odd way of writing if($i/text() ne 'becomes'), which
itself should probably be written if($i ne 'becomes') unless you really want
it to fail when the element contains comments or processing instructions.

Michael Kay
http://www.saxonica.com/




PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

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!

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.