title: XSLT conditions / variable scope
body: <pre><code>&lt;xsl:choose&gt;
      &lt;xsl:when test="long convoluted expression"&gt;
          &lt;xsl:element name="Class"&gt;123&lt;/xsl:element&gt;
          &lt;a lot more xsl:elements&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:when test="next very long expression"&gt;
          &lt;xml:element name="Class"&gt;124&lt;/xsl:element&gt;
          &lt;a lot more xsl:elements&gt;
      &lt;/xsl:when&gt;
      &lt;tens of more similar xsl:when&gt;
  &lt;/xsl:choose&gt;
  </code></pre>
  
  <p>Is there a way to simplify the above code with conditionals? For every class value the objects are given, there follows tens of rows with extra attributes. These attributes form sets according to the value of the class. Class 0-99 has one set of extra tags, class 100-199 a second, forming a maintenance nightmare when one of these extra tag sets change. </p>
  
  <p>I was considering a solution like this:</p>
  
  <pre><code>&lt;xsl:choose&gt;
      &lt;xsl:when test="long convoluted expression"&gt;
          &lt;xml:element name="Class"&gt;123&lt;/xsl:element&gt;
          &lt;xsl:variable name="outputclass" select="123"&gt;
      &lt;/xml:when&gt;
      &lt;xsl:when test="next very long expression"&gt;
          &lt;xml:element name="Class"&gt;124&lt;/xsl:element&gt;
          &lt;xsl:variable name="outputclass" select="124"&gt;
      &lt;/xsl:when&gt;
  &lt;/xsl:choose&gt;
  &lt;xsl:choose&gt;
      &lt;xsl:when test="$outputclass &gt; 99"&gt;
          &lt;xml:elements for classes 100-199 here&gt;
      &lt;/xsl:when&gt;
  &lt;xsl:choose&gt;
  </code></pre>
  
  <p>But of course this fails, as the outputclass variable is not in the same scope. Any way to go around this?</p>