And btw, you can remove everything key-related from the xsl and it still
doesn't pass the variable. The only thing slightly unusual in this is
selecting a node set from a variable with the apply-templates. It should
work but it's not something I exercise that much so if there's something
triggering a bug, that seems the most likely place.
On 3/10/23 01:25, Eric J. Schwarzenbach wrote:
Hi Sergey,
I get the same result as you (using xalan 2.7.3 RC). I'm quite
mystified why, because the code looks to me like it should work. I
tried various changes to make it work or expose what might be wrong,
but no luck.
On 3/9/23 16:12, Bederov, Sergey wrote:
Hello Eric,
Can you please take a look at the corrected XSLT? No errors now, but
for some reason the parameter is not being passed to the template.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:exslt="http://exslt.org/common">
<xsl:key name="keyname" match="Foo" use="@id"/>
<xsl:template match="Root">
<xsl:variable name="created">
<Created/>
</xsl:variable>
<xsl:apply-templates select="exslt:node-set($created)">
<xsl:with-param name="prm" select="@attr"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Created">
<xsl:param name="prm"/>
<Output>
<Display>
<xsl:value-of select="$prm"/>
</Display>
<Usage>
<xsl:value-of select="key('keyname',$prm)"/>
</Usage>
<Display>
<xsl:value-of select="$prm"/>
</Display>
</Output>
</xsl:template>
</xsl:stylesheet>
Xalan 2.7.2 output:
<Output xmlns:exslt="http://exslt.org/common"
xmlns:str="http://exslt.org/strings">
<Display/>
<Usage/>
<Display/>
</Output>
*Sergey Bederov
*Senior Developer
*Cortona3D**
*www.cortona3D.com <http://www.cortona3d.com/>
*From:*Bederov, Sergey
*Sent:* Thursday, March 2, 2023 10:01 AM
*To:* j-users@xalan.apache.org
*Subject:* RE: Xalan bug: key( ) clears variable
Hello,
Sorry, I didn’t know that the JRE Xalan and the official Xalan are
different things. Looking at the source code, the JRE version indeed
appears outdated.
The test data I provided originally reproduces the bug in the JRE
Xalan. For some reason their version ignores the “plmxml” prefix and
allows to call “key” on a non-existent key name. I downloaded the
official Xalan 2.7.2 and updated the XSLT file. Now it is as follows:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:exslt="http://exslt.org/common">
<xsl:key name="keyname" match="Foo" use="@id"/>
<xsl:template match="Root">
<xsl:variable name="created">
<Created/>
</xsl:variable>
<xsl:apply-templates select="exslt:node-set($created)">
<xsl:with-param name="prm" select="@attr"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Created">
<xsl:param name="prm"/>
<Output>
<Display>
<xsl:value-of select="$prm"/>
</Display>
<Usage>
<xsl:value-of select="key('keyname',$prm)"/>
</Usage>
<Display>
<xsl:value-of select="$prm"/>
</Display>
</Output>
</xsl:template>
</xsl:stylesheet>
In the official Xalan 2.7.2 it works even worse than in JRE: both
“Display” elements are empty. Looks like the parameter is not being
passed to the template. This might be connected to the fact that
“created” is not a node-set but a result-tree-fragment. But anyway,
how should I pass the parameter in this case?
In Saxon the example works fine: both “Display” elements contain the
correct value “foo”.
JRE Xalan:
<Output xmlns:exslt="http://exslt.org/common"
xmlns:str="http://exslt.org/strings">
<Display>foo</Display>
<Usage/>
<Display/>
</Output>
Xalan 2.7.2:
<Output xmlns:exslt="http://exslt.org/common"
xmlns:str="http://exslt.org/strings">
<Display/>
<Usage/>
<Display/>
</Output>
Saxon HE 11:
<Output xmlns:exslt="http://exslt.org/common"
xmlns:str="http://exslt.org/strings">
<Display>foo</Display>
<Usage/>
<Display>foo</Display>
</Output>
*Sergey Bederov
*Senior Developer
*Cortona3D**
*www.cortona3D.com <http://www.cortona3d.com/>