gpt4 book ai didi

java - Saxon:无法使用 XSLT 中的 xs:string 参数调用需要字符串的静态方法

转载 作者:行者123 更新时间:2023-11-29 07:13:51 26 4
gpt4 key购买 nike

我正在尝试从我的 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。假设“password”变量是 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 使用字符串方法?

[1] http://commons.apache.org/codec/api-release/org/apache/commons/codec/digest/DigestUtils.html#md5Hex(java.lang.String )

--更新:一位同事刚刚找到公司的 Saxon 9.4PE 许可证 key 。不幸的是,错误仍然存​​在,唯一改变的是 byte[] 方法的转换首选项从 24 变为 31。

最佳答案

您需要输入您的变量:

<xsl:variable as="xs:string" name="password" select="string(value[@type='password'][1])" />

或者在调用中使用它:

<xsl:value-of select="digest:md5Hex(xs:string($password))"
disable-output-escaping="yes" />

xs 命名空间定义为:

xmlns:xs="http://www.w3.org/2001/XMLSchema"

关于java - Saxon:无法使用 XSLT 中的 xs:string 参数调用需要字符串的静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11448305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com