[xquery-talk] Problem in validating XQuery

Morten Sørensen mortenss at mailme.dk
Sun Sep 30 23:47:40 PDT 2007


Hi all

I am quite new to XQuery and already faces the first problems, hope someone
can help me


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
<route><start>{$i/onto/road/text()}</start><dist>{$i/@distanceMiles}</dist>
                                                                            
            else if(fn:compare($i/text(), 'becomes')) then
<dist>{$i/@distanceMiles}</dist>
                                                                            
            else
()                                                                          
   
}
</straight>

I keep on getting the following validation error when running the query with
Saxon:

Error on line 20 column 77 of file:/C:/Eclipse_projects/XMLTech/driving.xq:
  XPST0003: XQuery syntax error in #...s}</dist> else () }#:
    '}' must be written as '}}' within element content Static error(s) in
query

I can simply not figure it out L

Driving.xml looks like this (some of it is left out due to size):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="driving.xslt"?> <drivingreport
  xmlns="http://www.example.org/driving"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.example.org/driving
                      driving.xsd">
  <directions durationHours="4" durationMinutes="33" lengthMiles="246.68">
    <startout compasDirection="NORTHWEST" distanceMiles="0.01">
      <on>PA-36 / N MAIN ST</on>
      <toward>LINCOLN AVE</toward>
    </startout>
    <drivedirections>
      <!-- step 1-10 -->
      <turnonto carturn="LEFT" distanceMiles="0.2">
        <onto>
          <road>LINCOLN AVE</road>
        </onto>
      </turnonto>
      <becomes distanceMiles="1.7">
        <road>LINCOLN AVE</road>
        <newroad>PA-436</newroad>
      </becomes>
      <turnonto carturn="RIGHT" distanceMiles="27.9">
        <onto>
          <road>US-119 S / BUFFALO-PITTSBURGH HWY</road>
        </onto>
      </turnonto>









..
    </drivedirections>
    <endat>1600 Pennsylvania Ave Nw, Washington, DC US</endat>
  </directions>
</drivingreport>

Thanx
Morten







More information about the talk mailing list