title: Is there a better way to do the following XSLT
body: <p>I am learning XSLT and doing some simple examples to get a better taste of it. I want to transform a XML file to html via XSLT. Here is my XML:</p>
  
  <pre><code>&lt;structure&gt;
      &lt;part class="H1" id="h11"/&gt;
      &lt;part class="H2" id="h21"/&gt;
      &lt;part class="H3" id="h31"/&gt;
      &lt;part class="H4" id="h41"/&gt;
      &lt;part class="H5" id="h51"/&gt;
      &lt;part class="H6" id="h61"/&gt;
  &lt;/structure&gt;
  &lt;style&gt;
      &lt;property part-name="h11" name="text"&gt;This is a h1 heading&lt;/property&gt;
      &lt;property part-name="h21" name="text"&gt;This is a h2 heading&lt;/property&gt;
      &lt;property part-name="h31" name="text"&gt;This is a h3 heading&lt;/property&gt;
      &lt;property part-name="h41" name="text"&gt;This is a h4 heading&lt;/property&gt;
      &lt;property part-name="h51" name="text"&gt;This is a h5 heading&lt;/property&gt;
      &lt;property part-name="h61" name="text"&gt;This is a h6 heading&lt;/property&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>And here is my simple XLST:</p>
  
  <pre><code>&lt;xsl:key name="headings" match="property[@name='text']" use="@part-name"/&gt;
  &lt;xsl:template match="part[@class='H1']"&gt;
      &lt;h1&gt;
          &lt;xsl:value-of select="key('headings', @id)"/&gt;
      &lt;/h1&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:key name="headings" match="property[@name='text']" use="@part-name"/&gt;
  &lt;xsl:template match="part[@class='H2']"&gt;
      &lt;h2&gt;
          &lt;xsl:value-of select="key('headings', @id)"/&gt;
      &lt;/h2&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="part[@class='H3']"&gt;
      &lt;h3&gt;
          &lt;xsl:value-of select="key('headings', @id)"/&gt;
      &lt;/h3&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="part[@class='H4']"&gt;
      &lt;h4&gt;
          &lt;xsl:value-of select="key('headings', @id)"/&gt;
      &lt;/h4&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="part[@class='H5']"&gt;
      &lt;h5&gt;
          &lt;xsl:value-of select="key('headings', @id)"/&gt;
      &lt;/h5&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="part[@class='H6']"&gt;
      &lt;h6&gt;
          &lt;xsl:value-of select="key('headings', @id)"/&gt;
      &lt;/h6&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>As you can see, it is very verbose and repetitive. Is there a way via some XPath expression to make it shorter and actually do the job in a better way? Perhaps, something like a regEx? 
  Another way I can think of is with the use of <code>&lt;xsl:if&gt;</code> and have the whole thing inside one single template, but that's not much of an improvement IMO. </p>