我正在尝试从我的 XSLT 样式表中调用静态 Java 方法:
<?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>
找到了 DigestUtils 类和静态 md5Hex 方法 [1]。问题是,调用该方法有三种可能的方式,即使用 byte[]、InputStream 或 String。鉴于“密码”变量的类型为 xs:string,我假设 Saxon 会自动选择最后一个选项。但相反,它坚持使用 byte[] 方法并相应地失败:
[...]
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.
有没有办法强制撒克逊人使用字符串方法?
-- 更新:一位同事刚刚找到了该公司的 Saxon 9.4PE 许可证密钥。不幸的是,错误仍然存在,唯一改变的是 byte[] 方法的转换首选项从 24 变为 31。