title: Is it possible to make xsl:template sensitive to the pushed-from node without using xsl:param?
body: <p>I'm pretty sure the answer to this is no, but since the only alternative is what I deem inelegant code, I thought I'd throw this out and see if I'm missing something while hoping this hasn't been asked.</p>
  
  <p>Given this source XML:</p>
  
  <pre><code>&lt;root&gt;
      &lt;p&gt;Hello world&lt;/p&gt;
      &lt;move elem="content" item="test"/&gt;
      &lt;p&gt;Another text node.&lt;/p&gt;
      &lt;content item="test"&gt;I can't &lt;b&gt;figure&lt;/b&gt; this out.&lt;/content&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I want this result:</p>
  
  <pre><code>&lt;root&gt;
      &lt;block&gt;Hello world&lt;/block&gt;
      &lt;newContent&gt;I can't &lt;hmmm&gt;figure&lt;/hmmm&gt; this out.&lt;/newContent&gt;
      &lt;block&gt;Another text node.&lt;/block&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>An ordinary language description:</p>
  
  <ol>
  <li>Replace &lt;move .../&gt; with the result of processing
  the element whose name matches move's @elem attribute and whose @item
  matches move's @item attribute (e.g., in this case the content of the element [&lt;content&gt;] is processed so &lt;b&gt; is replaced by &lt;hmm&gt;). </li>
  <li>Prevent the element from step 1 from
  being written out to the result tree in its original document order</li>
  </ol>
  
  <p>The problem is the input XML document will be considerably more complex and variable. And the stylesheet is a third-party transform that I am extending. The template I'd have to copy in order to use a mode-based solution is pretty significant in size and that seems inelegant to me. I know, for example, this would work:</p>
  
  <pre><code>&lt;xsl:template match="b"&gt;
      &lt;hmmm&gt;
          &lt;xsl:apply-templates/&gt;
      &lt;/hmmm&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="p"&gt;
      &lt;block&gt;
          &lt;xsl:apply-templates/&gt;
      &lt;/block&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="move"&gt;
      &lt;xsl:variable name="elem" select="@elem"/&gt;
      &lt;xsl:variable name="item" select="@item"/&gt;
      &lt;xsl:apply-templates select="//*[name()=$elem and @item=$item]" mode="copy-and-process"/&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="content"/&gt;
  &lt;xsl:template match="content" mode="copy-and-process"&gt;
              &lt;newContent&gt;&lt;xsl:apply-templates/&gt;&lt;/newContent&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>What I would like to do is have the &lt;xsl:template&gt; that matches "content" be sensitive to what node pushes to it. So, that I can have an &lt;xsl:template match="content"/&gt; that is only executed (and therefore its matching node and children are suppressed) when the node pushed from is &lt;root&gt; and not &lt;move&gt;. The virtue in this is that if the third-party stylesheet's relevant template is updated, I don't have to worry about updating a copy of the stylesheet that processes the &lt;content&gt; node. I'm pretty sure this isn't possible, but I thought it was worth asking about. </p>