title: add a class attribute to `<xsl:element>` under a certain condition
body: <p>I'm trying to add a class to <code>&lt;xsl:element&gt;</code> under a certain condition, I've an xml tag with an attribute called def, I need to add a class when ever this attribute exists.</p>
  
  <p>Here is the xslt element:</p>
  
  <pre><code>&lt;xsl:element name="{if (@id='123') then 'th' else 'td'} &gt;
  &lt;xsl:apply-template /&gt;
  &lt;/xsl:element&gt;
  </code></pre>
  
  <p>What i've tried:</p>
  
  <pre><code>&lt;xsl:attribute name="class"&gt;def-
          &lt;xsl:if test="fn:exists(@def)"&gt;
          &lt;xsl:value-of select="@def"/&gt;
          &lt;/xsl:if&gt;
      &lt;/xsl:attribute&gt;
      &lt;xsl:element name="{if (@role='rowhead' ) then 'th' else 'td'}" use-attribute-sets="{$class}" &gt;
  &lt;xsl:apply-templates /&gt;
      &lt;/xsl:element&gt;
  </code></pre>
  
  <p>I would like a matching expression of this:</p>
  
  <pre><code>&lt;th scope="row" class="def-{if (fn:exists(@def)) then @def else ''}"&gt;
  &lt;td scope="row" class="def-{if (fn:exists(@def)) then @def else ''}"&gt;
  </code></pre>
  
  <p>using:</p>
  
  <pre><code>&lt;xsl:element&gt;
  </code></pre>