Error running Saxonica query.exe (content item for axis step is absent)

Query.exe is the implementation of the Saxon XQuery command/engine. It’s a command line program that I’m running from the Windows command prompt.

Issue

<pre>
C:\XMLClass\XQuery>c:\Saxonica\bin\Query.exe -q:Flight3_Xquery.txt -o:flight3_xquery_out.xml
Error on line 2 column 20 of Flight3_Xquery.txt:
  XPDY0002: The context item for axis step root/descendant::FlightLeg is absent
Query failed with dynamic error: The context item for axis step root/descendant::FlightLeg is absent
</pre>

The above is a very confusing error for a simple mistake.
I didn’t pass an input file to the query.exe program with the -s: parameter ((source?), which indicates the xml data file on which to run the query. The -q: parameters (query) specifies the name of the query files itself. And the -o: parameter (output) specifies the output filename for the results of running the XQuery.

Corrected Parameters

<pre>
c:\XMLClass\XQuery>c:\Saxonica\bin\Query.exe -q:Flight3_Xquery.txt -s:c:\XMLClass\IntroSamples\Flight03.xml -o:flight3_xquery_out.xml
</pre>

Sample XQuery

The Flight3.XQuery.txt contains the following sample XQuery:

<pre>
(:  FLWOR = For Let Where Order-by Return   :) 
for $flightLeg in //FlightLeg
where $flightLeg/DepartureAirport = 'OKC' or $flightLeg/ArrivalAirport = 'OKC' 
order by $flightLeg/ArrivalDate[1] descending  
return $flightLeg
</pre>

Second Solution

Instead of passing the input filename on the -s parameter on the command line, the file could be embedded in the XQuery itself with a “doc(filename)” statement, as shown below:

(:  FLWOR = For Let Where Order-by Return   :) 
for $flightLeg in doc("c:\XMLClass\IntroSamples\Flight03.xml")//FlightLeg 
where $flightLeg/DepartureAirport = 'OKC' or $flightLeg/ArrivalAirport = 'OKC' 
order by $flightLeg/ArrivalDate[1] descending  
return $flightLeg

Uncategorized  

Leave a Reply