title: XSLT 2.0 - passing a node set as a parameter doesn't seem to work
body: <p>I have a document that I need to transform such that most elements are copied as-is, with some exceptions: for certain specified nodes, child elements need to be appended, and some of these child elements need to reference back to specific elements in the source document.  A separate "model/crosswalk" xml file contains the elements to add.  The elements in the crosswalk that need to refer back to the source document have "source" attributes that point them to specific elements.  Of course, my actual source docs (&amp; the actual crosswalk) are more complex and varied than these examples.</p>
  
  <p>Here is a source document example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
      &lt;album&gt;
          &lt;artist&gt;Frank Sinatra&lt;/artist&gt;
          &lt;title&gt;Greatest Hits&lt;/title&gt;
      &lt;/album&gt;
      &lt;album&gt;
          &lt;artist&gt;Miles Davis&lt;/artist&gt;
          &lt;title&gt;Kind Of Blue&lt;/title&gt;
      &lt;/album&gt;
      &lt;movie&gt;
          &lt;title&gt;ET&lt;/title&gt;
          &lt;director&gt;Steven Spielberg&lt;/director&gt;
      &lt;/movie&gt;
      &lt;movie&gt;
          &lt;title&gt;Blues Brothers&lt;/title&gt;
          &lt;director&gt;John Landis&lt;/director&gt;
      &lt;/movie&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Here is the "crosswalk" (crswlk.xml):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;root&gt;
      &lt;album&gt;
          &lt;artist-info&gt;
              &lt;artist2 source="artist"/&gt;
          &lt;/artist-info&gt;
      &lt;/album&gt;
      &lt;movie&gt;
          &lt;director-info&gt;
              &lt;director2 source="director"/&gt;
          &lt;/director-info&gt;
      &lt;/movie&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>And here is the desired output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
      &lt;album&gt;
          &lt;artist&gt;Frank Sinatra&lt;/artist&gt;
          &lt;title&gt;Greatest Hits&lt;/title&gt;
          &lt;artist-info&gt;
              &lt;artist2&gt;Frank Sinatra&lt;/artist2&gt;
          &lt;/artist-info&gt;
      &lt;/album&gt;
      &lt;album&gt;
          &lt;artist&gt;Miles Davis&lt;/artist&gt;
          &lt;title&gt;Kind Of Blue&lt;/title&gt;
          &lt;artist-info&gt;
              &lt;artist2&gt;Miles Davis&lt;/artist2&gt;
          &lt;/artist-info&gt;
      &lt;/album&gt;
      &lt;movie&gt;
          &lt;title&gt;ET&lt;/title&gt;
          &lt;director&gt;Steven Spielberg&lt;/director&gt;
          &lt;director-info&gt;
              &lt;director2&gt;Steven Spielberg&lt;/director2&gt;
          &lt;/director-info&gt;
      &lt;/movie&gt;
      &lt;movie&gt;
          &lt;title&gt;Blues Brothers&lt;/title&gt;
          &lt;director&gt;John Landis&lt;/director&gt;
          &lt;director-info&gt;
              &lt;director2&gt;John Landis&lt;/director2&gt;
          &lt;/director-info&gt;
      &lt;/movie&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Here's my xslt:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt;
  &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt;
      &lt;xsl:strip-space elements="*"/&gt;
  
      &lt;xsl:variable name="crosswalk" select="document('crswlk.xml')"/&gt;
  
      &lt;xsl:template match="node()|@*"&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="@* | node()"/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="*/album|movie"&gt;
          &lt;xsl:variable name="theNode" select="."/&gt;
          &lt;xsl:variable name="nodeName" select="name()"/&gt;
          &lt;xsl:element name="{$nodeName}"&gt;
              &lt;xsl:apply-templates select="@* | node()"/&gt;
              &lt;xsl:apply-templates select="$crosswalk//*[name()=$nodeName]/*"&gt;
                  &lt;xsl:with-param name="curNode" select="$theNode"/&gt;
              &lt;/xsl:apply-templates&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="*[@source]"&gt;
          &lt;xsl:param name="curNode" /&gt;
          &lt;xsl:variable name="sourceNodeName" select="@source"/&gt;
          &lt;xsl:element name="{name()}"&gt;
              &lt;xsl:value-of select="$curNode//*[name()=$sourceNodeName]"/&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>This stops processing once that last template tries to access <code>$curNode</code> for the first time.  When I run the xslt in Eclipse (Xalan 2.7.1) it throws this error: " java.lang.ClassCastException: org.apache.xpath.objects.XString cannot be cast to org.apache.xpath.objects.XNodeSet".</p>
  
  <p>If I pass a similar nodeset as a parameter to a template that matches nodes from the source document, it works as expected - the nodeset is accessible.  However, passing the nodeset to the last template above doesn't work.  Is it because the template matches nodes from the external document?  I sure don't know.  Any help much appreciated, it took me a while just to get to this point.  Thanks!</p>