X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=tests%2Fscripts%2Fxpath.sh;fp=tests%2Fscripts%2Fxpath.sh;h=abb32b425c501ec0e3d376fe0d398b2d61ddbffc;hb=2b1c3cc37c5ee3385190e6d2f915733b6abb7374;hp=0000000000000000000000000000000000000000;hpb=6a86f6e048fd6c2d5768e413c469a87d7bb54eb5;p=SXSI%2Fxpathcomp.git diff --git a/tests/scripts/xpath.sh b/tests/scripts/xpath.sh new file mode 100755 index 0000000..abb32b4 --- /dev/null +++ b/tests/scripts/xpath.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +COUNT=0 +QUERY="" +FILE="" + +function usage { + echo "usage: $0 [options] " + echo "options:" + echo "-c counting mode" + echo "-h display this help" +} + +for i in "$@" +do + if [ "$i" == "-h" ] + then + usage + exit 0 + elif [ "$i" == "-c" ] + then + COUNT=1 + continue + elif [ "$QUERY" == "" ] + then + QUERY="$i" + continue + else + FILE="$i" + fi +done + +if [ -z "$FILE" ] +then + echo "error: missing filename" + usage + exit 1 +fi + + +if [ "$COUNT" == "0" ] +then + xmlstarlet sel -t -m "$QUERY" -c . -n "$FILE" +else + xmlstarlet sel -t -v "count($QUERY)" "$FILE" +fi