绕过 Xalan XSLT 中的延迟变量评估

Bypass lazy variable evaluation in Xalan XSLT

我正在处理我们用来处理 XML 文件的 XSLT,如果存在元素,我需要触发一些操作。创建了一个 Java 扩展,认为我可以简单地设置一个它会像这样评估的变量:

<xsl:for-each select="//attachments/attachment" xmlns:fbattach="java://com.package.ProcessAttachment">
    <xsl:variable name="content"><xsl:value-of select="filedata" /></xsl:variable>
    <xsl:variable name="fileName"><xsl:value-of select="name"  /></xsl:variable>
    <xsl:variable name="fileType"><xsl:value-of select="fileType" /></xsl:variable>
    <xsl:variable name="attachmentId"><xsl:value-of select="fbattach:test($fileName, $fileType, $content)" /></xsl:variable>
</xsl:for-each>

我看到的问题是 attachmentId 似乎没有得到评估,除非我这样做:

<attatchment2><xsl:value-of select="$attachmentId" /></attatchment2>

Xalan 似乎在延迟评估变量,仅在用于输出时才进行评估。 This and this 似乎证实了这一理论。

有没有办法强制求值,比如设置什么的?

如果要确保对表达式求值,一种方法是在 xsl:message (https://www.w3.org/TR/xslt-10/#message).

中使用它