#! /bin/sh
#==========================================================================#
# Script to drive validation of XML documents with Saxon (XSLT engine).    #
# Saxon version used : 9 HE                                                #
# This script is used to validate PNML documents against their constraints #
# expressed by Schematron rules. The same constraints are expressed as 	   #
# OCL constraints in the PNML meta-models.                                 #
#                                                                          #
# Invocation    : ./validatePNML.sh constraintsFiles.sch PNMLFile.pnml     # 
#                                                                          #
# Author        : L. Hillah                                                #
# Contributors  : C. Démoulins                                             #
# License       : GNU GPL v3 (See http://www.gnu.org/licenses/)            #
# Revisions     : 1/Mar 2, 2010/L.H. + C.D./ Inception                     #
#                 2/Mar 2, 2010/L.H./ Documentation                        #
#                 3/Jun 16, 2010/L.H./ Upgraded to Saxon 9 2.1.1.          #
#==========================================================================#

# Directory where http://www.schematron.com/tmp/iso-schematron-xslt2.zip was
# uncompressed. Replace by your own.
SCHEMATRONDIR="/Users/lom/Documents/PNML/bin/iso-schematron-xslt2"

[ $# -eq 0 ] && echo "Usage: `basename $0` constraintsFile PNMLFile" && exit 1

xslt () {
	java -jar /Users/lom/Documents/PNML/bin/saxonhe9-2-1-1j/saxon9he.jar $@
}

# 1) Processes inclusions
xslt -xsl:$SCHEMATRONDIR/iso_dsdl_include.xsl  -s:$1 > $1.xsl1 || exit 1

# 2) Expands abstract patterns
xslt -xsl:$SCHEMATRONDIR/iso_abstract_expand.xsl -s:$1.xsl1 > $1.xsl2 || exit 1

# 3) Compiles the schema 
# Have execution traces and reports in SVRL format (which is XML-based) at step 4.
#xslt -xsl:$SCHEMATRONDIR/iso_svrl_for_xslt2.xsl  -s:$1.xsl2 > $1.xsl3 || exit 1

# 3) Compiles the schema
# Have minimal reports at step 4
xslt -xsl:$SCHEMATRONDIR/iso_schematron_skeleton_for_saxon.xsl -s:$1.xsl2 > $1.xsl3 || exit 1

# 4) Validates the PNML document. You may redirect the output to a file 
# (For instance, in case you activate the SVRL report)
xslt -xsl:$1.xsl3 -s:$2 || exit 1

