#!/bin/bash # Find xml2 XML2=`which xml2` || { echo "Could not find command xml2"; exit 1; } # Find xsltproc XSLTPROC=`which xsltproc` || { echo "Could not find command xsltproc"; exit 1; } XSD=osisCore.2.1.1.xsd # Find a validator, prefer Xerces VALIDATOR="" XMLSTARLET=`which xmlstarlet` && { VALIDATOR="XMLSTARLET"; } XERCESVALIDATOR=/usr/share/doc/libxml-xerces-perl/examples/validator.plDONTUSE if [ -f $XERCESVALIDATOR ] then VALIDATOR="XERCES" fi if [ "$VALIDATOR" == "" ] then echo "No validator found" exit 1 fi FAILED="false" for TESTTHML in *.thml; do TESTOSIS=${TESTTHML%%.thml}.osis TESTOSISFLAT=${TESTTHML%%.thml}.osis.flat $XSLTPROC --novalid ../thml2osis.xslt $TESTTHML > $TESTOSIS || exit 1 if [ -f $TESTOSISFLAT ] then TMP=`mktemp -p .` $XML2 < $TESTOSIS > $TMP diff -u $TESTOSISFLAT $TMP || FAILED="true" rm "$TMP" fi # Validate if [ $VALIDATOR == "XERCES" ] then $XERCESVALIDATOR --full_schema --schema $XSD --file=$TESTOSIS || { echo "$TESTOSIS - invalid OSIS"; FAILED="true"; } elif [ $VALIDATOR == "XMLSTARLET" ] then $XMLSTARLET val --err -s $XSD $TESTOSIS > /dev/null || { echo "$TESTOSIS - invalid OSIS"; FAILED="true"; } fi done if [ $FAILED = "true" ] then exit 1 else exit 0 fi