The difference is that inside square brackets, the context node changes. So @e refers to an e attribute of the item in $bar that you're testing (it hasn't got one), whereas if you use the variable, @e is referring to an attribute of the my:element element.
If you want to avoid declaring a variable, you can use current()/@e - current() is the node that was current at the outermost level of the XPath expression, ie. outside the square brackets.
Michael Kay

From: [] On Behalf Of Cary Millsap
Sent: 10 November 2004 15:51
To: 'Saxon Help List'
Subject: [saxon] Can't use an attribute reference

I’m using Saxon-B 8.1 (by the way, I get a “file not found” error at sourceforge when I try to download 8.1.1).

Can anyone help me understand why the two <line> elements don’t have the same value in the output of the transform below? (You can use any file as input to this transform.)


Cary Millsap
Hotsos Enterprises, Ltd.
Nullius in verba

Upcoming events:
- Performance Diagnosis 101: 1/4
Calgary, 2/2 Sydney
- SQL Optimization 101: 11/8
Dallas, 12/13 Atlanta, 2/7 Sydney
- Hotsos Symposium 2005: March 6–10
- Visit for schedule details...



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


<xsl:transform version="2.0"







       <xsl:output indent="yes"/>


       <xsl:variable name="data">

              <my:element e="314.782"/>



       <xsl:template match="/">

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











              <xsl:variable name="max-height" select="932.108"/>

              <xsl:variable name="i" select="1 + round($data/my:element/@e div $max-height * 8)"/>


                     <xsl:for-each select="$data/my:element">

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

                           <line>$bar[f(@e)] = <xsl:value-of select="$bar[1 + round(@e div $max-height * 8)]"/></line>

                           <line>$bar[f($e)] = <xsl:value-of select="$bar[1 + round($e div $max-height * 8)]"/></line>