Fork me on GitHub

Project Notes

#434 Saxon Processor

Setting up and using Saxon for XSLT, XQuery, and XML Schema, including XSLT 3.0 compatible processing on macOS.

Notes

On macOS, xsltproc is installed by default as part of the libxslt. This is handy for baseline handling of XSLT, however it only supports XSLT 1.1 features.

The Saxon processor is the leading alternative for XSLT, XQuery, and XML Schema, including the only XSLT 3.0 conformant toolset.

Let’s install and test Saxon on macOS.

macOS Installation

Here are the steps I used to setup Saxon for use on macOS.

We need Java…

$ brew install openjdk
$ java --version
openjdk 25.0.1 2025-10-21
OpenJDK Runtime Environment Homebrew (build 25.0.1)
OpenJDK 64-Bit Server VM Homebrew (build 25.0.1, mixed mode, sharing)

Download the latest Saxon package, available from the downloads page or GitHub.

$ wget https://github.com/Saxonica/Saxon-HE/releases/download/SaxonHE12-9/SaxonHE12-9J.zip
$ unzip SaxonHE12-9J.zip -d SaxonHE12-9J
$ java -cp "./SaxonHE12-9J/saxon-he-12.9.jar:./SaxonHE12-9J/lib/*" net.sf.saxon.Transform -?
SaxonJ-HE 12.9 from Saxonica
Usage: see https://www.saxonica.com/documentation/index.html#!using-xsl/commandline
Format: net.sf.saxon.Transform options params
Options available: -? -a -catalog -config -dtd -ea -expand -explain -export -ext -im -init -it -jit -json -l -lib -license -nogo -now -ns -o -opt -or -outval -p -quit -r -relocate -repeat -s -sa -scmin -strip -stublib -t -T -target -threads -TJ -Tlevel -Tout -TP -TPxsl -traceout -tree -u -val -versionmsg -warnings -x -xi -xmlversion -xsd -xsdversion -xsiloc -xsl -y --?
Use -XYZ:? for details of option XYZ
Params:
  param=value           Set stylesheet string parameter
  +param=filename       Set stylesheet document parameter
  ?param=expression     Set stylesheet parameter using XPath
  !param=value          Set serialization parameter

Defining a handy alias for invoking Saxon:

alias xslt3="java -cp \"$(pwd)/SaxonHE12-9J/saxon-he-12.9.jar:$(pwd)/SaxonHE12-9J/lib/*\" net.sf.saxon.Transform"

Transform Example

I am using the books.xml collection from LCK#431 XSLT, but now using an enhanced transformer books.xsl that demonstrates some XSLT 2.0 and 3.0 features, specifically:

  • XSLT 2.0 Features
    • lower-case(), upper-case(), replace()
    • tokenize() and string-join()
    • for-each-group (grouping, big upgrade over 1.0)
    • inline if (...) then ... else ... expressions
    • user-defined functions (xsl:function)
  • XSLT 3.0 Features
    • xsl:mode on-no-match="shallow-skip" (clean default processing)
    • expand-text="yes" allows {expr} directly in text (much cleaner syntax)
    • more functional style with xsl:sequence

Running the transform:

xslt3 -s:../books.xml -xsl:books.xsl -o:books.html

See the result in books.html:

books.png

Credits and References

About LCK#434
XSLTXQueryXML SchemamacOS

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

Project Source on GitHub Return to the LittleCodingKata Catalog
About LittleCodingKata

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

Follow the Blog follow projects and notes as they are published in your favourite feed reader