BUG: XML Context Method Can Traverse Out of Xsl:template Element (284453)



The information in this article applies to:

  • Microsoft XML 2.0
  • Microsoft XML 2.5
  • Microsoft XML 2.6
  • Microsoft XML 3.0
  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft Internet Explorer (Programming) 5.01 SP1
  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q284453

SYMPTOMS

When you use the context method of the "http://www.w3.org/TR/WD-xsl" namespace, it is possible to use a negative value for the index parameter from an xsl:template element, effectively navigating the context out of the template. It should not be possible to do this because the template can be called from more than one location, which means that the value of context(-n) changes depending on how the template is called.

RESOLUTION

This problem is discussed here for reference purposes only, because the context method has been superceded by the current method of the "http://www.w3.org/1999/XSL/Transform" namespace.

Use the current method and its corresponding namespace instead of the context method.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Insert the following code into a new text document, and save the file as repro.xml:
    <?xml version="1.0" ?>
    <?xml-stylesheet type="text/xsl" href="repro.xsl" ?> 
    <Data>
       <StudentBody>
          <Student name="Jon Burchel">
          </Student>
       </StudentBody>
    </Data>
    					
  2. Insert the following text into another new document, and save the file as repro.xsl in the same location as the XML file you just created:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    
    <xsl:template match="/">
       <HTML>
          <BODY>
             <xsl:apply-templates select = "Data/StudentBody/*" />
          </BODY>
       </HTML>
    </xsl:template>
    
    <xsl:template match="Student">
       <!-- context() is OK -->
       <LI><xsl:value-of select = "@name" /></LI><BR/>
       <xsl:if test="context()[$not$ end()]"><BR/></xsl:if>
    
       <!-- context(-2) should not be possible -->
       <B>This should not work!!!</B><BR/>
       <LI><xsl:value-of select = "@name" /></LI><BR/>
       <xsl:if test="context(-2)[$not$ end()]"><BR/></xsl:if>
    </xsl:template>
    
    </xsl:stylesheet>
    					
  3. Browse to repro.xml by using Internet Explorer (IE). The template should not be able to query the negative context, but it does so successfully.

Modification Type:MajorLast Reviewed:6/4/2003
Keywords:kbbug kbMSXMLnosweep kbpending KB284453