gpt4 book ai didi

java - XSLT 2.0 - 迭代 Java 对象列表

转载 作者:行者123 更新时间:2023-12-01 14:59:02 27 4
gpt4 key购买 nike

我有一个 XSL,旨在创建 XML 的副本,但向 XML 中的某些元素添加了一些属性。 XSL 调用一个 Java 函数,该函数返回 CInfo 类型的对象列表 (java.util.List),CInfo 目前是一个非常简单的类,定义如下:

public class CInfo {
public int getNewVal() {
return 12345;
}
}

我现在在 XSL 中遇到以下代码片段的问题:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:list="java.util.List"
xmlns:saxon="http://saxon.sf.net/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
...
...>

...
<xsl:variable name="infoList"
select="up:computeUpdates($updator)"/>

<xsl:for-each select="$infoList">
<xsl:variable name="cinfo" select="."/>
<xsl:variable name="newVal" select="ci:getNewVal($cinfo)"/>
...
...
</xsl:for-each>

computeUpdates()(我验证确实是由 XSL 调用的)返回一个仅包含一个 CInfo 类型实例的列表。问题发生在 xsl:for-each 处,它给出以下错误:

Error on line 89
XPTY0019: Required item type of first operand of '/' is node(); supplied value has item
type java:com.mproj.mpkg.CInfo
at xsl:for-each (#76)
processing "com.mproj.mpkg.."
at xsl:apply-templates (#48)

不知何故,XSL 似乎无法迭代infoList。奇怪的是,我正在处理的代码库中的现有 XSL 具有非常相似的 for-each ,并且能够迭代另一个类的 Java 对象列表(尽管与 CInfo 类似),但不能似乎没有任何问题。我错过了什么吗?使 XSLT 迭代 Java 对象列表的标准过程是什么?有什么例子可以帮助我吗?我尝试在网络上搜索此类循环的示例以及上述问题的可能解决方案,但到目前为止尚未成功。

最佳答案

您没有向我们展示出现错误的第 89 行。我的猜测是它可能包含以下形式的表达式

$infoList/XXXXX

这是失败的,因为(如错误消息所解释的)“/”的 lh 操作数必须是节点序列。

关于java - XSLT 2.0 - 迭代 Java 对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13954110/

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