Skip to content

Running with XProc

Amanda Galtman edited this page Apr 11, 2024 · 19 revisions

Introduction

XProc is a language to define XML pipelines. It is a W3C recommendation and there are several XProc implementations.

Run an XSpec test with XProc

In order to run XSpec tests with XProc an XProc implementation needs to be installed. As an example, this description uses XML Calabash with the Saxon XProc harness (for XSLT or for XQuery). Harnesses for some other XQuery processors, including BaseX, are available.

  1. Download the zip file of XML Calabash latest release and unzip it to a local path (e.g., /tmp/xmlcalabash for Linux/macOS or C:\xmlcalabash for Windows). Make sure you download the zip file because libraries are required (that is, using only the jar file won't work). XML Calabash version 1.1.27-99 is used here.

  2. Make sure Java is installed, e.g.:

    java -version
    
  3. Make sure XSpec is available in a local path (e.g. /tmp/xspec for Linux/macOS or C:\xspec for Windows).

  4. Navigate to your XSpec directory.

  5. Run an XSpec test for XSLT as follows:

    For Linux/macOS:

    java -jar /tmp/xmlcalabash/xmlcalabash-1.2.5-99.jar \
         -i source=tutorial/escape-for-regex.xspec \
         -o result=tutorial/escape-for-regex-result.html \
         -p xspec-home=file:/tmp/xspec/ \
         src/harnesses/saxon/saxon-xslt-harness.xproc

    For Windows:

    java -jar C:\xmlcalabash\xmlcalabash-1.2.5-99.jar ^
         -i source=tutorial/escape-for-regex.xspec ^
         -o result=tutorial/escape-for-regex-result.html ^
         -p xspec-home=file:///C:/xspec/ ^
         src\harnesses\saxon\saxon-xslt-harness.xproc

    where:

    • -jar is the XML Calabash jar file
    • -i source is the input port with the XSpec test to be executed
    • -o result is the output port where the HTML report will be stored
    • -p xspec-home is the absolute URI of the XSpec installation
    • saxon-xslt-harness.xproc is the Saxon XProc harness for XSLT

    The output result from the command line may look like this:

    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:Testing with SAXON HE 9.9.1.2
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:No escaping
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:Must not be escaped at all
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:Test simple patterns
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:..When encountering parentheses
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:escape them.
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:..When encountering a whitespace character class
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:escape the backslash
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:result should have one more character than source
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:When processing a list of phrases
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:All phrase elements should remain
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46:Strings should be escaped and status attributes should be added
    INFO : src/harnesses/saxon/saxon-xslt-harness.xproc:41:46: FAILED
    INFO : src/harnesses/harness-lib.xpl:267:45:passed: 5 / pending: 0 / failed: 1 / total: 6

    The HTML report file is created in the location specified by -o result=.

  6. Run an XSpec test for XQuery as follows:

    Make sure to use saxon-xquery-harness.xproc.

    For Linux/macOS:

    java -jar /tmp/xmlcalabash/xmlcalabash-1.2.5-99.jar \
         -i source=tutorial/xquery-tutorial.xspec \
         -o result=tutorial/xquery-tutorial-result.html \
         -p xspec-home=file:/tmp/xspec/ \
         src/harnesses/saxon/saxon-xquery-harness.xproc

    For Windows:

    java -jar C:\xmlcalabash\xmlcalabash-1.2.5-99.jar ^
         -i source=tutorial/xquery-tutorial.xspec ^
         -o result=tutorial/xquery-tutorial-result.html ^
         -p xspec-home=file:///C:/xspec/ ^
         src\harnesses\saxon\saxon-xquery-harness.xproc

    Output:

    INFO : src/harnesses/harness-lib.xpl:267:45:passed: 1 / pending: 0 / failed: 0 / total: 1
Clone this wiki locally