SourceForge Project Page

Instructions for the Xalan extension


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"

Using the "generate" function

To generate a barcode use the barcode:generate(NodeList, String) function:

  1. NodeList: the barcode configuration (See example below and the Barcode XML format).
  2. String: the message to be encoded

Here's an example:

      <xsl:variable name="barcode-cfg">
      <xsl:copy-of select="barcode:generate($barcode-cfg, '0123456789')"/>

Using the barcode extension element

Xalan has a bug that causes a NullPointerException in FOP. Please use the extension function above until a new Xalan version is release. The bug is fixed in the codebase but no release has happened since.

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:

      <barcode:barcode message="0123456789" orientation="90">

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