#!/bin/bash function usage () { echo "" echo "Run as $0 " echo "E.g. xsd_to_mds.bat C:\\CDWALite-xsd-public-v1-1.xsd cdwalite CDWALite" echo "" } # Check for 3 cmd line args if [ -z "$3" ]; then usage fi # xsd input file and setName of mds file for output xsd=$1 mds=$2 if [ ! -f "$xsd" ]; then echo "XSD file $xsd does not exist." exit -1 fi if [ "x$GSDLHOME" = "x" ]; then echo "No GSDLHOME set. Source the (gs3-)setup.(ba)sh file in your Greenstone before running this script." exit -1 fi outputdir= if [ "x$GSDL3SRCHOME" != "x" ]; then outputdir=$GSDL3SRCHOME else outputdir=$GSDLHOME fi outputfile=$outputdir/gli/metadata/$mds.mds xsl=$outputdir/gli/classes/xml/xsd-to-mds.xsl if [ ! -f "$xsl" ]; then echo "XSLT file $xsl can't be found." exit -1 fi # See internal wiki page Writing_XSL#Running_ApplyXSLT_to_apply_an_XSLT_file_from_the_command_line # Bash doesn't like quotes (escaped quotes) around _any_ of the file paths below. mycmd="java -cp $GSDLHOME/bin/java/xalan.jar:$GSDLHOME/bin/java/ApplyXSLT.jar:$GSDLHOME/bin/java/. org.nzdl.gsdl.ApplyXSLT -t $xsl -x $xsd -o $outputfile" # Call the command $mycmd status=$? # http://stackoverflow.com/questions/11079017/operations-on-boolean-variables if [ $status != 0 ]; then echo "*** Failed running: $mycmd" echo "Return status: $status" exit -1 elif [ ! -e "$outputfile" ]; then echo "**** XSLT transform failed: the file $outputfile was not generated. Ran command:" echo "$mycmd" exit -1 else echo "The file $outputfile has been generated." fi echo ""