Created
April 17, 2014 14:22
-
-
Save dirkk/10987298 to your computer and use it in GitHub Desktop.
Run an XQuery with several different processors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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