QR barcode for FOP 0.20.5

One of our clients asked us if we can add QR barcode to the PDF documents they use. The problem was that they use pretty old FOP – 0.20.5. For barcodes we proposed to use barcode4j library + fop0.20.5 extension. But in the latest version it doesn’t support QR codes, so we had to build jars from the development code, replace old JARs with new ones and add ZXing core library.

PS … and they use Java 1.5 so we had to compile ZXing for this one …

Gennady Kim

Comparing an XML text element against a list of choices in XSLT

When I need to compare some XML text element against several strings, I could compare it with each of the strings but I prefer to use the contains() function.

For example, there are 3 lists of possible qualifiers for LIN-02/04/06/…/30:

  • SKU: CB, SK, IN, BP, OT, IT
  • Vendor Part Number: VI, VN, VP, VC, VA, MN, MG
  • UPC: UP, UA, UI, UK

And XML like this:

<LIN>
	<LIN01>000010</LIN01>
	<LIN02>VN</LIN02>
	<LIN03>ABC-123456</LIN03>
	<LIN04>OT</LIN04>
	<LIN05>998877</LIN05>
</LIN>

If I used the “direct” way to find item’s SKU number, I would have to create something like this:

<xsl:choose>
  <xsl:when test="(LIN02 = 'CB' or LIN02 = 'SK' or LIN02 = 'IN' or LIN02 = 'BP' or LIN02 = 'OT' or LIN02 = 'IT')">
    <xsl:value-of select="LIN03" />
  </xsl:when>
  <xsl:when test="(LIN04 = 'CB' or LIN04 = 'SK' or LIN04 = 'IN' or LIN04 = 'BP' or LIN04 = 'OT' or LIN04 = 'IT')">
    <xsl:value-of select="LIN05" />
  </xsl:when>
...
  <xsl:when test="(LIN30 = 'CB' or LIN30 = 'SK' or LIN30 = 'IN' or LIN30 = 'BP' or LIN30 = 'OT' or LIN30 = 'IT')">
    <xsl:value-of select="LIN31" />
  </xsl:when>
</xsl:choose>

But there is an elegant, clear and short way to do the same. I prefer something like this:

<xsl:variable name="skuQuals" select="'~CB~SK~IN~BP~OT~IT~'" />
<xsl:value-of select="./*[contains(name(), 'LIN') and (number(substring-after(name(), 'LIN')) mod 2 = 0) and contains($skuQuals, concat('~', text(), '~'))]/following-sibling::*"/>

Gennady Kim