I'm quite sure you're sick of the sound of my typing by now,
but there's just one more thing I'd like to ask about.
I think it's a bug, but the recommendation isn't (to my
mind) quite clear about it.


Sablotron throws an error if you declare a variable inside
a for-each loop. The second time the loop is executed, you
get "conflicting variable bindings".


This seems intuitively wrong, and it would be very useful
to make such declarations. If you're writing a nested loop
you may want access to the context of the outer loop from
within the inner. And declaring a variable in the outer loop
is a simple way to do that, e.g.

<xsl:for-each select="$x">
  <xsl:variable name="x_node" select="."/>
  <xsl:variable name="x_name" select="name()"/>
  <xsl:for-each select="$y[name()=$x_name]">
     <blah x="{$x_node/@foo}" y="{@foo}"/>
  </xsl:for-each>
</xsl:for-each>

The only alternative is to use recursive <xsl:call-template/>
invocations instead, which can be much less readable.

I attach an example stylesheet and document which cause this error.


Many many thanks for all your incredibly speedy bug-fixes yesterday.
I am most impressed :-)

 .robin.
<foo>
 <bar/>
 <baz/>
 <quux/>
</foo>
<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet[
 <!ENTITY nl  "<xsl:text>&#xA;</xsl:text>">
]>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/*">
    <xsl:for-each select="*">
      <xsl:variable name="name" select="name()"/>
      <xsl:element name="{$name}"/>&nl;
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Reply via email to