title: Applying templates to elements in a variable/sequence
body: <p>When I use "apply-templates" and select a variable sequence, does the template act upon the context of the element in the sequence, or does it act upon the context of the element in the document?</p>
  
  <p>In the below example, it seems to do either, or none, but I don't understand why. </p>
  
  <pre><code>&lt;root&gt;
  &lt;a/&gt;
  &lt;b/&gt;
  &lt;c&gt;&lt;a/&gt;&lt;/c&gt;
  &lt;a/&gt;
  &lt;/root&gt;
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"&gt;
  &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt;
  &lt;xsl:template match="root"&gt;
      &lt;!--this variable give me a sequence of "a" elements--&gt;
      &lt;xsl:variable name="someElementA1" select="//a"/&gt;
      &lt;xsl:variable name="someElementA2"&gt;
          &lt;xsl:copy-of select="//a"/&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:for-each select="$someElementA1/a"&gt;
          &lt;xsl:element name="test"&gt;
              &lt;xsl:text&gt;This is scenario 1: &lt;/xsl:text&gt;
              &lt;xsl:apply-templates select="."/&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:for-each&gt;
      &lt;xsl:for-each select="$someElementA2/a"&gt;
          &lt;xsl:element name="test"&gt;
              &lt;xsl:text&gt;This is scenario 2: &lt;/xsl:text&gt;
              &lt;xsl:apply-templates select="."/&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:for-each&gt;
      &lt;xsl:element name="test"&gt;
          &lt;xsl:text&gt;This is scenario 3: &lt;/xsl:text&gt;
          &lt;xsl:apply-templates select="$someElementA1"/&gt;
      &lt;/xsl:element&gt;
      &lt;xsl:element name="test"&gt;
          &lt;xsl:text&gt;This is scenario 4: &lt;/xsl:text&gt;
          &lt;xsl:apply-templates select="$someElementA2/a"/&gt;
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  &lt;!--these are the templates to apply--&gt; 
  &lt;xsl:template match="a[parent::c]"&gt;
      &lt;xsl:text&gt;This element has a parent&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="a[parent::root]"&gt;
      &lt;xsl:text&gt;This element is in the root element&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="a"&gt;
      &lt;xsl:text&gt;This element is in the sequence&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>&lt;test&gt;This is scenario 2: This element is in the sequence&lt;/test&gt;
  &lt;test&gt;This is scenario 2: This element is in the sequence&lt;/test&gt;
  &lt;test&gt;This is scenario 2: This element is in the sequence&lt;/test&gt;
  &lt;test&gt;This is scenario 3: This element is in the root elementThis element has a parentThis element is in the root element&lt;/test&gt;
  &lt;test&gt;This is scenario 4: This element is in the sequenceThis element is in the sequenceThis element is in the sequence&lt;/test&gt;
  </code></pre>