git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/xpathcomp@1191
3cdefd35-fc62-479d-8e8d-
bae585ffb9ca
--- /dev/null
+#!/bin/bash
+
+COUNT=0
+QUERY=""
+FILE=""
+
+function usage {
+ echo "usage: $0 [options] <query> <file>"
+ 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