Java 将值存储在变量中的XSLT
我有一个正在工作的项目,它使用XSLT显示来自db(db2)的数据。我在做一些变量,比如Java 将值存储在变量中的XSLT,java,xslt,jakarta-ee,Java,Xslt,Jakarta Ee,我有一个正在工作的项目,它使用XSLT显示来自db(db2)的数据。我在做一些变量,比如 <xsl:variable name="RatePerLoadedMiles1"> <xsl:call-template name="ratePerLoadedMiles"> <xsl:with-param name="summaryRow" select="$SummaryRow1" /> <xsl:with-param n
<xsl:variable name="RatePerLoadedMiles1">
<xsl:call-template name="ratePerLoadedMiles">
<xsl:with-param name="summaryRow" select="$SummaryRow1" />
<xsl:with-param name="numerator" select="$OperatingExpense1"/>
</xsl:call-template>
</xsl:variable>
我也在用它做一些额外的计算
<td class="rightAligned"><!-- RPLM -->
<xsl:call-template name="formatAsPercent">
<xsl:with-param name="numberToFormat">
<xsl:call-template name="divideNumbers">
<xsl:with-param name="numerator" select="$RatePerLoadedMiles1 +
$RatePerLoadedMilesBefore +
$RatePerLoadedMilesAfter" />
<xsl:with-param name="denominator" select="3" />
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</td>
输出来自浏览器
网页错误详细信息
用户代理:Mozilla/4.0(兼容;MSIE8.0;WindowsNT6.1;WOW64;
Trident/4.0;EasyBits GO v1.0;SLCC2;.NET CLR 2.0.50727;.NET CLR
3.5.30729;.NET CLR 3.0.30729;Media Center PC 6.0;.NET4.0C;MDDR;
FDM)时间戳:2011年8月9日星期二14:24:01 UTC
消息:对变量或参数“RatePerLoadedMiles”的引用
无法解决。变量或参数可能未定义,或
它可能不在范围之内
行:1385字符:2代码:0 URI:
xsl:variable
的内容用作序列构造函数。在问题中提供的示例片段中,变量将填充一组0个或多个节点或原子值,这些节点或原子值由xsl:call template
指令本身返回。变量的值是(在XSLT 1.0中)一个“结果树片段”,从技术上讲,它是一个带有子节点的文档节点,除了对你能用它做什么有限制。但如果将其用作字符串,则可以有效地获取文档节点的字符串值,如果将其用作数字,则可以将该字符串转换为数字
但这与错误消息无关,错误消息表示您正在从其范围外引用变量。您的问题的答案是,变量RatePerLoadedMiles1存储值5(如@Michael Kay所述,作为RTF)。当引用
$RatePerLoadedMiles1
时,不会重新评估它
如果它给了您发布的错误消息,那么您在引用它时显然忘记了末尾的
1
,因为错误消息说RatePerLoadedMiles
您是否运行了模板?请给我们看看你的输出。问号在哪里?我看不到确切的问题。我已使用“?”:)更新了问题,并显示了从浏览器收到的错误消息。xml是在运行时生成的,因此如果不在运行时进行调试,我将无法进行调试(我知道)。您似乎引用了错误范围内的变量。问题是什么?我用粗体字写了这个问题。这是我目前最关心的问题……我已经阅读了,除非我是盲人,否则它似乎无法回答我的问题。我实际上已经更改了变量名,但没有重新复制错误消息(因为除了变量名之外,它是相同的)。系统对其他xsl文档有一定的依赖性,由于命名冲突,我以前收到过相同的消息,所以我尝试快速更改名称。
<td class="rightAligned"><!-- RPLM -->
<xsl:call-template name="formatAsPercent">
<xsl:with-param name="numberToFormat">
<xsl:call-template name="divideNumbers">
<xsl:with-param name="numerator" select="$RatePerLoadedMiles1 +
$RatePerLoadedMilesBefore +
$RatePerLoadedMilesAfter" />
<xsl:with-param name="denominator" select="3" />
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</td>