You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Eric J. Schwarzenbach" <er...@wrycan.com> on 2023/03/01 01:14:06 UTC

Re: Xalan bug: key( ) clears variable

FWIW, I tried the following very low effort test. I happen to have some 
shell scripts set up for running arbitrary xsls (currently using XalanJ 
2.7.1) from the command line using org.apache.xalan.xslt.Process.

When running using the submitted xsl and input xml, it errors with

(Location of error unknown)org.xml.sax.SAXException: Can not resolve 
namespace prefix: plmxml

When I fixed that and tried again it errored with

Line #36; Column #60; java.lang.RuntimeException: There is no xsl:key 
declaration for nonexistentkey!

The rendered output was

<?xml version="1.0" encoding="UTF-8"?><Output 
xmlns:exslt="http://exslt.org/common" 
xmlns:str="http://exslt.org/strings"><Display/>

It looks to me like thIs error is what causes the prm variable to never 
get omitted. Sergey, you did not provide a copy of the actual output you 
were getting. Is it the same as what I show above? Is it possible your 
transform is similarly being terminated in the middle, and perhaps you 
were just not being provided the error?


On 2/27/23 21:19, Joseph Kesselman wrote:
> Have we checked whether this is one of our past fixes, or at least 
> whether it can be reproduced in the official Xalan?
>
> If it can't, having the user switch to the Apache code will solve 
> their problem (at the expense of having to do the endorsed-libraries 
> dance) or patch their JRE).
>
> If it can, and hasn't already been logged as a known issue, we should 
> add it to the backlog.
>
> --
>    /_  Joe Kesselman (he/him/his)
> -/ _) My Alexa skill for New Music/New Sounds fans:
>    /   https://www.amazon.com/dp/B09WJ3H657/
>
> () Plaintext Ribbon Campaign
> /\ Stamp out HTML mail!
> ------------------------------------------------------------------------
> *From:* Bederov, Sergey <be...@cortona3d.com>
> *Sent:* Monday, February 27, 2023 12:03:23 PM
> *To:* j-users@xalan.apache.org <j-...@xalan.apache.org>
> *Subject:* Xalan bug: key( ) clears variable
>
> Hello,
>
> I am using the Xalan engine which is embedded into the OpenJDK. On 
> versions JDK15 to JDK21 an incorrect behavior is observed, which looks 
> like a bug in Xalan.
>
> XSLT:
>
> <xsl:stylesheet version="2.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> xmlns:str="http://exslt.org/strings" 
> xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="plmxml">
>
> <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('nonexistentkey',$prm)"/>
>
> </Usage>
>
> <Display>
>
> <xsl:value-of select="$prm"/>
>
> </Display>
>
> </Output>
>
> </xsl:template>
>
> </xsl:stylesheet>
>
> XML:
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <Root attr="foo"/>
>
> The problem is that in the second template, when the “key” function is 
> called, the “prm” variable is for some reason cleared. In the output 
> file, the first “Display” element contains the correct value “foo”, 
> but the second “Display” element is empty. Why does it happen? It’s a 
> variable which should always have the same value.
>
> Yes, here the “key” function is called for a key which doesn’t exist, 
> but it’s not the cause of the problem. If a key is present, and if it 
> contains the required value, the bug is still there. Actually the 
> “key” function doesn’t find anything anyway, as if the variable was 
> already empty.
>
> I see that the Xalan development is ongoing, so I thought it would be 
> useful to report this bug.
>
> *Sergey Bederov
> *Senior Developer
> *Cortona3D
> *www.cortona3D.com <http://www.cortona3D.com>
>