Just found a work around. If I make the variable a parameter then this works fine.

 

Mark

 

From: Mark Gabriel [mailto:mgabriel@limehousesoftware.co.uk]
Sent: 13 August 2009 09:15
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] Lazy evaluation of variable with scope problem. Bug?

 

Here we go...  run this on itself with and without the commented message.

 

In the mean while it there a better way to force the evaluation of the variable before the context changes?

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

                <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

               

                <xsl:variable name="items" as="element()">

                                <items>

                                                <item key="A"></item>

                                                <item key="A"></item>

                                                <item key="B"></item>

                                                <item key="B"></item>

                                                <item key="A"></item>

                                                <item key="A"></item>

                                                <item key="B"></item>

                                                <item key="C"></item>

                                </items>

                </xsl:variable>

               

                <xsl:template match="/">

                                <items>

                                                <xsl:apply-templates select="$items/item"/>

                                </items>

                </xsl:template>

               

                <xsl:template match="item">

                                <xsl:copy>

                                                <xsl:copy-of select="@*"/>

                                                <xsl:variable name="key" select="@key"/>

                                                <!--<xsl:message select="$key"/>-->

                                                <xsl:number count="*[@key = $key]" from="items" format="1"/>

                                </xsl:copy>

                </xsl:template>

                               

</xsl:stylesheet>

 

Mark

 

From: Michael Kay [mailto:mike@saxonica.com]
Sent: 12 August 2009 17:41
To: 'Mailing list for the SAXON XSLT and XQuery processor'
Subject: Re: [saxon] Lazy evaluation of variable with scope problem. Bug?

 

On the face of it, this certainly looks like a bug (in variable inlining). Could you supply a repro please?

 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay

 


From: Mark Gabriel [mailto:mgabriel@limehousesoftware.co.uk]
Sent: 12 August 2009 17:13
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Lazy evaluation of variable with scope problem. Bug?

Hi all,

 

I’m using Saxon 9.1.0.5J on the command line and trying to debug and profile some code from within out application and I’ve found this:

 

<xsl:variable name="autoNumberKey" select="string(@lhs:autoNumberKey)"/>

<xsl:number count="*[@lhs:autoNumberKey = $autoNumberKey]" from="document" level="any" format="1”/>

 

Seems to produce a different result to:

 

<xsl:variable name="autoNumberKey" select="string(@lhs:autoNumberKey)"/>

<xsl:message select="$autoNumberKey"/>

<xsl:number count="*[@lhs:autoNumberKey = $autoNumberKey]" from="document" level="any" format="1”/>

 

Should this really be happening??

 

How can I code around this to count all elements with the same @lhs:autoNumberKey value as the current node?

 

Regards

 

Mark

 


Mark Gabriel
Development

-------------------------------
mgabriel@limehousesoftware.co.uk
Limehouse Software Ltd

DDI:  01628 640 452
Main: 01628 640 401        
Fax:  01628 640 461         

Limehouse Software Limited
St Cloud Gate
St Cloud Way
Cookham Road
Maidenhead, Berks
SL6 8XD

www.limehousesoftware.co.uk - Unifying Information

Limehouse Software Limited - An Objective Company
         
The information contained in this e-mail or in any attachments is confidential and is intended solely for the named addressee only. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, please notify Limehouse Software Ltd immediately by returning this e-mail to sender or calling 01628 640 401 and do not read, use or disseminate the information. Opinions expressed in this e-mail are those of the sender and not necessarily the company. Although an active anti-virus policy is operated, the company accepts no liability for any damage caused by any virus transmitted by this e-mail, including any attachments.