title: How to mimic calling template-match with a parameter value?
body: <p>I'm looking for a workaround on passing parameters to a template-match. I'm aware this isn't allowed within XPath, and therefore I'm looking for a 'plan B' solution. </p>
  
  <p>This is what I wished would work :</p>
  
  <p>Part 1 of xslt (2.0) :</p>
  
  <pre><code>&lt;xsl:template match="/"&gt;
      &lt;xsl:for-each select="//Main/PageList/Page"&gt;
      &lt;xsl:result-document href="{@ID}.xml"&gt;
          &lt;Page ID="{@ID}"&gt;
              &lt;xsl:apply-templates select="node()"&gt;
                  &lt;xsl:with-param name="theID" select="@ID"/&gt;
              &lt;/xsl:apply-templates&gt;
          &lt;/Page&gt;
      &lt;/xsl:result-document&gt;
      &lt;/xsl:for-each&gt; 
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>So fairly straightforward, don't bother about the tags used, what it does in essence is go through a node, and for each node it creates a single XML file. Each node starts with an ID, and it's this ID I'd like to make available for other templates. Unfortunately this works fine for named templates, but it doesn't work for matched ones (if I understood the theory correctly at least)</p>
  
  <p>So below is what I'd like to see working :</p>
  
  <pre><code>&lt;!-- identity template --&gt;
      &lt;xsl:template match="node()|@*"&gt;
      &lt;xsl:param name="theID"/&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="node()|@*"&gt;
              &lt;xsl:with-param name="theID" select="$theID"/&gt;
          &lt;/xsl:apply-templates&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;!-- lots of templates here doing what I want them to do --&gt;
  
  &lt;!-- one template creating an issue --&gt;
  
  &lt;xsl:template match="@src"&gt;
  &lt;!-- would be nice to know the current ID, but unfortunately this one stays empty... --&gt;
  &lt;xsl:param name="theID"/&gt;
  
  &lt;!-- clean current attribute a bit --&gt;
  &lt;xsl:variable name="S1" select="replace(.,'\.\.\/','')"/&gt;
  
  &lt;xsl:attribute name="src"&gt;
  &lt;xsl:choose&gt;
  &lt;xsl:when test="contains($S1,'common')"&gt;
  &lt;!-- just use current value, don't bother about current ID --&gt;
      &lt;xsl:value-of select="$S1"/&gt;
  &lt;/xsl:when&gt;
  &lt;xsl:otherwise&gt;
      &lt;!-- use ID parameter --&gt;
      &lt;xsl:value-of select="concat($theID,'_',$S1)"/&gt;
  &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  &lt;/xsl:attribute&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Don't look at the code as such, it's just a smaller part of the whole file, but the essence is that I want to use the ID parameter from my first part (match="/") inside the other template (match="@src"), but this seems to be rather complex. </p>
  
  <p>Am I missing something ? If I'm just having bad luck and it's not possible indeed, would anyone have an advice how I could proceed ?</p>
  
  <p>Thanks in advance !</p>