<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>30171</bug_id>
          
          <creation_ts>2017-08-25 23:21:32 +0000</creation_ts>
          <short_desc>Can a global variable declaration refer to an imported variable it is overriding?</short_desc>
          <delta_ts>2017-10-29 23:21:40 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XSLT 3.0</component>
          <version>Proposed Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Kay">mike</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>128856</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2017-08-25 23:21:32 +0000</bug_when>
    <thetext>Consider a stylesheet module a.xsl that contains the global variable declaration

&lt;xsl:variable name=&quot;v&quot; xml:id=&quot;v1&quot; select=&quot;23&quot;/&gt;

Now consider a stylesheet module b.xsl that does

&lt;xsl:import href=&quot;a.xsl&quot;&gt;
&lt;xsl:variable name=&quot;v&quot;  xml:id=&quot;v2&quot; select=&quot;$v+1&quot;/&gt;
&lt;xsl:template name=&quot;xsl:initial-template&quot;&gt;{$v}&lt;/xsl:template&gt;

My immediate instinct is that the second variable declaration (v2) is an error: a variable is not in scope within its own declaration. But there appears to be a reading of the spec that suggests that the stylesheet should output 24.

9.5 tells us that v1 declares a global variable $v that is visible &quot;everywhere except within its own declaration, and where it is shadowed by another binding&quot;.

In the select expression of v2, is the variable declared by v1 visible? It&apos;s not within its own declaration. Is it shadowed by another binding - specifically by the binding v2?

[Definition: A binding shadows another binding if the binding occurs at a point where the other binding is visible, and the bindings have the same name. ]

This definition suggests that v2 shadows v1. But there is something missing in the definition. A local variable v shadows a global variable v, but only within the scope of the local variable v. The pertinent phrase is &quot;where it is shadowed&quot;. So is v1 shadowed by v2 *within the select expression of v2*, given that v2 is not visible here? 

This question applies equally to XSLT 1.0 and 2.0. I don&apos;t think either of those specs tells us the answer.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128857</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2017-08-26 07:46:43 +0000</bug_when>
    <thetext>I have written a test case for this situation: variable-0120.

I think it was always the WG&apos;s intent that this should be an error, and I think we should issue a clarifying erratum to say so.

(I) In 9.9 para 2, change

A global variable binding element is visible everywhere in the containing package (including other stylesheet modules) except within the xsl:variable or xsl:param element itself and any region where it is shadowed by another variable binding. 

to

A global variable binding element is visible everywhere in the containing package (including other stylesheet modules) except (a) within the xsl:variable or xsl:param element itself, (b) within any other global variable declaration binding a variable with the same name, and (c) within any region where it is shadowed by another variable binding. 

(II) Also in 9.9, change the definition of &quot;shadows&quot; from

[Definition: A binding shadows another binding if the binding occurs at a point where the other binding is visible, and the bindings have the same name. ]

to

[Definition: Within a region of the stylesheet where a binding B1 is visible, B1 shadows another binding B2 having the same name as B1 if B1 occurs at a point where B2 is visible.]</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128928</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2017-10-13 20:18:50 +0000</bug_when>
    <thetext>Erratum E5 has been drafted.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128950</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2017-10-29 23:21:40 +0000</bug_when>
    <thetext>The erratum was reviewed and accepted with one change: it should be classified as substantive rather than editorial.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>