title: XSLT: Apply templates with conditional parameters?
body: <p>I'd like to apply a template with different parameters based on the result of a conditional. Something like this:</p>
  
  <pre><code>&lt;xsl:choose&gt;
      &lt;xsl:when test="@attribute1"&gt;
          &lt;xsl:apply-templates select='.' mode='custom_template'&gt;
              &lt;xsl:with-param name="attribute_name" tunnel="yes"&gt;Attribute no. 1&lt;/xsl:with-param&gt;
              &lt;xsl:with-param name="attribute_value" tunnel="yes"&gt;&lt;xsl:value-of select="@attribute1"/&gt;&lt;/xsl:with-param&gt;
          &lt;/xsl:apply-templates&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:when test="@attribute2"&gt;
          &lt;xsl:apply-templates select='.' mode='custom_template'&gt;
              &lt;xsl:with-param name="attribute_name" tunnel="yes"&gt;Attribute no. 2&lt;/xsl:with-param&gt;
              &lt;xsl:with-param name="attribute_value" tunnel="yes"&gt;&lt;xsl:value-of select="@attribute1"/&gt;&lt;/xsl:with-param&gt;
          &lt;/xsl:apply-templates&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
          &lt;xsl:apply-templates select='.' mode='custom_template'&gt;
              &lt;xsl:with-param name="attribute_name" tunnel="yes"&gt;Error&lt;/xsl:with-param&gt;
              &lt;xsl:with-param name="attribute_value" tunnel="yes"&gt;No matching attribute   &lt;/xsl:with-param&gt;
              &lt;/xsl:apply-templates&gt;
      &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  </code></pre>
  
  <p>First of all, I suspect that this could be resolved in a much, much better way. (I'm entirely new to XSLT, so please suggest improvements and forgive the bloated code.)</p>
  
  <p>Now for the question: how could I've set the parameters based on this conditional, and still used them in an <code>xsl:apply-templates</code>? I've tried to wrap the entire <code>xsl:choose</code> with a <code>xsl:apply-templates</code> start-/end-tag, but that's apparently not legal. Any clues?</p>