I am trying to call a static Java method from my XSLT stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:digest="java:org.apache.commons.codec.digest.DigestUtils">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="user">
<user>
<firstname>
<xsl:value-of select="value[@type='firstname'][1]" />
</firstname>
<lastname>
<xsl:value-of select="value[@type='name'][1]" />
</lastname>
<password>
<xsl:variable name="password" select="string(value[@type='password'][1])" />
<xsl:value-of select="digest:md5Hex($password)"
disable-output-escaping="yes" />
</password>
</user>
</xsl:template>
The DigestUtils class is found and the static md5Hex-method [1] as well. The problem is, that there are three possible ways to invoke the method, namely with a byte[], an InputStream or a String. Given that the "password" variable is of type xs:string, I assumed that Saxon would automatically choose the last option. But instead, it insists on the byte[]-method and fails accordingly:
[...]
Loading org.apache.commons.codec.digest.DigestUtils
Looking for method md5Hex in Java class class org.apache.commons.codec.digest.DigestUtils
Number of actual arguments = 1
[...]
Trying method md5Hex: name matches
Method is static
Method has 1 argument; expecting 1
Found a candidate method:
public static java.lang.String org.apache.commons.codec.digest.DigestUtils.md5Hex(byte[])
Trying method md5Hex: name matches
Method is static
Method has 1 argument; expecting 1
Found a candidate method:
public static java.lang.String org.apache.commons.codec.digest.DigestUtils.md5Hex(java.io.InputStream) throws java.io.IOException
Trying method md5Hex: name matches
Method is static
Method has 1 argument; expecting 1
Found a candidate method:
public static java.lang.String org.apache.commons.codec.digest.DigestUtils.md5Hex(java.lang.String)
[...]
Finding best fit method for arguments
Trying option 0: public static java.lang.String org.apache.commons.codec.digest.DigestUtils.md5Hex(byte[])
Conversion preferences are [24]
Trying option 1: public static java.lang.String org.apache.commons.codec.digest.DigestUtils.md5Hex(java.io.InputStream) throws java.io.IOException
Conversion preferences are [80]
Trying option 2: public static java.lang.String org.apache.commons.codec.digest.DigestUtils.md5Hex(java.lang.String)
Conversion preferences are [80]
Eliminating option 1
Eliminating option 2
Number of candidate methods remaining: 1
Error at xsl:template on line 14 column 30 of migrate_users.xsl:
Cannot convert from xs:string to byte
Failed to compile stylesheet. 1 error detected.
Is there a way to force Saxon to use the String-method?
-- update: A colleague just found the company's license key for Saxon 9.4PE. Unfortunately the error persists, the only thing that changed was that the conversion preference for the byte[]-method went from 24 to 31.