POSTS

XSL - Transformer configuration exception error checking type expression funcall replace

Problem:

javax.xml.transform.TransformerConfigurationException: Error checking type of the expression ‘funcall(replace,

Solution:

Make sure to be using an updated xsl transalation engine like, for instance, saxon 9.

Maven dependency:


net.sf.saxon
Saxon-HE
9.8.0-3

Usage example:

public ProductPool process(FeedProduct feedProduct) throws Exception { File stylesheet = new File("src/main/resources/XMLToCSVStyle.xsl"); File xmlSource = new File(feedFileName); File csvTarget = new File(feedFileName.replace(".xml", ".csv")); TransformerFactory tFactory = TransformerFactory.newInstance(); // TransformerFactoryImpl tFactoryImpl = (TransformerFactoryImpl) tFactory; // net.sf.saxon.Configuration saxonConfig = tFactoryImpl.getConfiguration(); try { Transformer transformer = tFactory.newTransformer(new StreamSource(stylesheet)); StreamSource inputTarget = new StreamSource(xmlSource); StreamResult outputTarget = new StreamResult(csvTarget); transformer.transform(inputTarget, outputTarget); } catch (Exception e) { e.printStackTrace(); } return null; } \]\]>  

XMLToCSVStyle.xsl

<?xml version="1.0"?><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" omit-xml-declaration="yes" indent="no"/> <xsl:template match="/">xxx,yyy,...,zzzz <xsl:for-each select="//<root\_node\_name>"> <xsl:variable name="s1" select="concat('&quot;',xxx,'&quot;,&quot;',yyy,'&quot;,&quot;',...,'&quot;,&quot;',zzz,'&#xA;')"/> <xsl:value-of select="replace($s1, 'from', 'to')"/> <xsl:value-of select="$s1"/> </xsl:for-each> </xsl:template></xsl:stylesheet>\]\]>