Project

Profile

Help

$source-doc variable wrongly evaluated

Added by Anonymous almost 19 years ago

Legacy ID: #3450631 Legacy Poster: Evan Lenz (elenz)

Hello Michael, I stumbled over a juicy bug when working with 6.5.3, and I confirmed that it's still a problem in 6.5.5. To reproduce, run this stylesheet against a document other than itself: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="VAR1"> <xsl:for-each select="document('')"> <xsl:value-of select="$source-doc"/> </xsl:for-each> </xsl:variable> <xsl:variable name="source-doc" select="/"/> <xsl:template match="/"> <!-- This should copy the source document; instead it copies the stylesheet document --> <xsl:copy-of select="$source-doc"/> </xsl:template> </xsl:stylesheet> Even though $VAR1 isn't used, its definition causes $source-doc to be incorrectly evaluated, as if the expression "/" were evaluated inline in the context in which $source-doc is first referenced (inside the $VAR1 definition). This has a sticky effect, causing all subsequent evaluations to be wrong. My workaround was to move the $source-doc definition above the $VAR1 definition so that it comes first. Evan


Replies (1)

RE: $source-doc variable wrongly evaluated - Added by Anonymous almost 19 years ago

Legacy ID: #3450765 Legacy Poster: Michael Kay (mhkay)

Thanks Evan, certainly a juicy bug. It's amazing how long such things can lurk (and of course, how they always emerge a week or so after the first release in months or years). Saxon 6.x evaluates global variables eagerly (before it does anything else) and generally they are evaluated each in turn; however if there's a forwards reference from one global variable to another then the referenced variable is evaluated when the reference is encountered, and it seems it is evaluated with the context set to exactly what it is at the point where the variable reference appears. I've fixed the source code, it will probably take a while before I do another release. Michael Kay

    (1-1/1)

    Please register to reply