@ECHO OFF

if '%1 == ' goto no-params

if %1 == help goto myhelp

if not exist %1 goto no-xml-file

if not exist %2 goto no-xquery-file

if '%3 == ' goto no-output-file

set rootdir=..\..\..

set oldCLASSPATH=%CLASSPATH%
set oldPath=%Path%

set which_saxon=saxon

set CLASSPATH=%rootdir%\%which_saxon%\saxon9ee.jar
set CLASSPATH=%CLASSPATH%;.;C:\SAXON-license\

echo ---------------------------------------------------------
echo Running the XQuery Processor, Saxon, with the following specifications:
echo    - XML File: %1
echo    - XQuery File: %2
echo    - Output File: %3
echo ---------------------------------------------------------
echo.

java -classpath %CLASSPATH% net.sf.saxon.Query  -o %3 -s %1 %2

echo.
echo Done.
echo.
set path=%oldPath%
goto eof

:no-params
    cls
    echo Oops! You need to run the batch file with 3 arguments.
    echo Here's how to use it ...
    echo.
    echo Usage: "run-saxon <xml filename> <xquery filename> <output filename>"
    echo.
    goto eof

:myhelp
    cls
    echo Usage: "run-saxon <xml filename> <xquery filename> <output filename>"
    echo.
    goto eof

:no-xml-file
   cls
   echo Oops! %1 does not exist
   echo Most likely reason: mistyped filename
   echo Exiting ...
   echo.
   goto eof

:no-xquery-file
   cls
   echo Oops! %2 does not exist
   echo Most likely reason: mistyped filename
   echo Exiting ...
   echo.
   goto eof

:no-output-file
   cls
   echo Oops! You must specify an output file
   echo Exiting ...
   echo.
   goto eof

:no-saxon-jar
   cls
   echo Oops! Missing this saxon file: %rootdir%\%which_saxon%\saxon9ee.jar
   echo Most likely reason: saxon not installed in the correct directory
   echo Exiting ...
   goto eof

:eof

