Instructions for the SAXON extension
Introduction
This page describes how to generate barcodes in SVG format within an XSLT stylesheet that is processed with the SAXON XSLT Processor from Michael Kay.
Using the barcode extension for SAXON
This package contains an extension for SAXON for generating barcodes in SVG format. It has been tested with SAXON 8.8 but should work with version 8.7.1 and later. The extension is found under "src/saxon8".
To make to barcode extension available in your XSLT stylesheets, do the following:
- Add barcode4j.jar to the classpath. (Barcode4J must have been compiled with SAXON support in the first place.)
- Add the following namespace declaration to the root element of your XSLT stylesheet: xmlns:barcode="java:/org.krysalis.barcode4j.saxon8.BarcodeExtensionElementFactory"
- Add the barcode namespace prefix to the extension element prefixes: extension-element-prefixes="barcode"
Here's an example:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:barcode= "java:/org.krysalis.barcode4j.saxon8.BarcodeExtensionElementFactory" extension-element-prefixes="barcode">
To generate a barcode use simply use the "barcode" element in your template as indicated in the example:
<fo:block> <fo:instream-foreign-object> <barcode:barcode message="{msg}" orientation="90"> <barcode:code128> <barcode:height>8mm</barcode:height> </barcode:code128> </barcode:barcode> </fo:instream-foreign-object> </fo:block>
The XML syntax used within the barcode element is the Barcode XML.
The attribute "orientation" specifies the orientation of the barcode in degrees. The attribute is optional and if set must be one of the following values: 0, 90, -90, 180, -180, 270, -270.
Extension for SAXON 6.5.x
Barcode4J contains an extension for SAXON 6.5.x but it is no longer maintained and not part of the binary distribution anymore. The extension is found under "src/saxon".
The usage of the old SAXON extension is similar to the one above with the following differences:
- The "orientation" attribute is not supported.
- The URI for the barcode extension is "http://barcode4j.krysalis.org/org.krysalis.barcode4j.saxon.BarcodeExtensionElementFactory" instead of "java:/org.krysalis.barcode4j.saxon8.BarcodeExtensionElementFactory".
by Jeremias Märki