Skip to content

Instantly share code, notes, and snippets.

@dirkk
Created April 17, 2014 14:22
Show Gist options
  • Save dirkk/10987298 to your computer and use it in GitHub Desktop.
Save dirkk/10987298 to your computer and use it in GitHub Desktop.
Run an XQuery with several different processors
#!/bin/bash
# Copyright Dirk Kirsten, 2014
# show program usage
show_usage() {
echo "xquery usage: xquery [-fhiq]"
echo " Use different XQuery processors to evaluate an XQuery"
echo " -f XQuery file"
echo " -h help"
echo " -i input file"
echo " -q XQuery expression"
exit
}
BXARG=
SXARG=
XQARG=
ZOARG=
QUERY=
while getopts ":hi:f:q:" opt; do
case $opt in
i)
BXARG=$BXARG" -i $OPTARG"
SXARG=$SXARG" -s:$OPTARG"
ZOARG=$ZOARG" --context-item $OPTARG"
XQARG=$XQARG" -i $OPTARG"
;;
q)
QUERY=$OPTARG
;;
f)
QUERY=`cat $OPTARG`
;;
h)
show_usage ;;
\?)
echo "Invalid option: -$OPTARG" >&2
show_usage
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
show_usage
exit 1
;;
esac
done
# BaseX
echo "BaseX"
echo "---------------------"
basex $BXARG -q $QUERY
echo
echo
# Saxon
# Skip the first declaration line and use 2 spaces as indentation
echo "Saxon"
echo "---------------------"
saxon $SXARG -qs:$QUERY \!indent=yes | sed -e 's/<?xml version="1.0" encoding="UTF-8"?>//g'
echo
echo
# Zorba
echo "Zorba"
echo "---------------------"
zorba $ZOARG -i -q $QUERY | sed -e 's/<?xml version="1.0" encoding="UTF-8"?>//g'
echo
echo
# XQilla
echo "xqilla"
echo "---------------------"
TMP=/tmp/xqilla
echo $QUERY >> $TMP
xqilla $XQARG $TMP
rm $TMP
echo
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment