我有一个XSL,用于创建XML的副本,但在XML中的某些元素中添加了一些属性 . XSL调用一个Java函数,该函数返回CInfo类型对象的列表(java.util.List),该列表当前是一个非常简单的类,定义如下:
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对象列表的标准过程是什么?有什么例子可以帮助我吗?我尝试在网上搜索这种循环的例子以及上述问题的可能解决方案但到目前为止都没有成功 .
1 回答
您没有向我们展示第89行,其中出现错误 . 我的猜测是它可能包含表单的表达式
$ infoList / XXXXX
失败的原因是(正如错误消息所解释的)“/”的lh操作数必须是一系列节点 .