XSLT: copy XML with some minor changes

Today I worked on an XSLT style which copies XML into the same XML but with couple of changes. There were hundreds of elements so I created the following XSLT (example):

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<xsl:template match="/">
		<xsl:for-each select="*">
			<xsl:call-template name="copyElement"/>

	<xsl:template name="copyElement">
		<xsl:variable name="segName" select="name(.)" />
		<xsl:element name="{$segName}">
			<xsl:for-each select="@*">
				<xsl:attribute name="{name(.)}">
					<xsl:value-of select="."/>

				<xsl:when test="contains($segName, 'SegmentName')">
					<!-- custom code -->

			<xsl:if test="normalize-space(text()) != ''">
				<xsl:value-of select="normalize-space(.)"/>

			<xsl:for-each select="*">
				<xsl:call-template name="copyElement"/>

Gennady Kim


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