forked from usnistgov/metaschema-xslt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmvn-xsd-schema-xsl.sh
executable file
·49 lines (37 loc) · 1.39 KB
/
mvn-xsd-schema-xsl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
# Fail early if an error occurs
set -Eeuo pipefail
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") METASCHEMA_SOURCE XSD_RESULT [ADDITIONAL_ARGS]
Produces an XSD (XML Schema Definition) from a valid and well-ordered NIST (ITL/CSD) metaschema (Metaschema instance) using Saxon invoked from Maven.
Please install Maven first.
Additional arguments are provided to SaxonHE - see https://www.saxonica.com/documentation11/#!using-xsl/commandline
EOF
}
if ! [ -x "$(command -v mvn)" ]; then
echo 'Error: Maven (mvn) is not in the PATH, is it installed?' >&2
exit 1
fi
[[ -z "${1-}" ]] && { echo "Error: METASCHEMA_SOURCE not specified"; usage; exit 1; }
METASCHEMA_SOURCE=$1
[[ -z "${2-}" ]] && { echo "Error: XSD_RESULT not specified"; usage; exit 1; }
XSD_RESULT=$2
ADDITIONAL_ARGS=$(shift 2; echo ${*// /\\ })
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
POM_FILE="${SCRIPT_DIR}/../../support/pom.xml"
MAIN_CLASS="net.sf.saxon.Transform" # Saxon defined in pom.xml
if [ -e "$XSD_RESULT" ]
then
echo "Deleting prior $XSD_RESULT ..."
rm -f ./$XSD_RESULT
fi
mvn \
-f "$POM_FILE" \
exec:java \
-Dexec.mainClass="$MAIN_CLASS" \
-Dexec.args="-xsl:${SCRIPT_DIR}/nist-metaschema-MAKE-XSD.xsl -s:\"$METASCHEMA_SOURCE\" -o:\"$XSD_RESULT\" $ADDITIONAL_ARGS"
if [ -e "$XSD_RESULT" ]
then
echo "XSD schema written to file $XSD_RESULT"
fi