Instructions for the Xalan extension
Introduction
This page describes how to generate barcodes in SVG format within an XSLT stylesheet that is processed with Apache Xalan-J.
Using the barcode extension for Apache Xalan
This package contains an extension for Apache Xalan for generating barcodes in SVG format.
To make to barcode extension available in your XSLT stylesheets, do the following:
- Add barcode4j.jar to the classpath.
- Add the following namespace declaration to the root element of your XSLT stylesheet: xmlns:barcode="org.krysalis.barcode4j.xalan.BarcodeExt"
- 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="org.krysalis.barcode4j.xalan.BarcodeExt" extension-element-prefixes="barcode">
Using the "generate" function
To generate a barcode use the barcode:generate(NodeList, String) function:
- NodeList: the barcode configuration (See example below and the Barcode XML format).
- String: the message to be encoded
Here's an example:
<fo:block> <fo:instream-foreign-object> <xsl:variable name="barcode-cfg"> <barcode> <code128> <height>8mm</height> </code128> </barcode> </xsl:variable> <xsl:copy-of select="barcode:generate($barcode-cfg, '0123456789')"/> </fo:instream-foreign-object> </fo:block>
Using the barcode extension element
To generate a barcode, simply put a barcode element in the namespace declared above into your stylesheet. The barcode element currently takes one attribute: message.
Here's an example:
<fo:block> <fo:instream-foreign-object> <barcode:barcode message="0123456789" 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.
by Jeremias Märki