title: How to make on xml field an attribute of another field?
body: <p>I have the following xml file:</p>
  
  <pre><code>&lt;generic_etd&gt;
    &lt;dc.contributor&gt;NSERC&lt;/dc.contributor&gt;
    &lt;dc.creator&gt;gradstudent&lt;/dc.creator&gt;
    &lt;dc.contributor&gt;John Smith&lt;/dc.contributor&gt;
    &lt;dc.contributor.role&gt;Advisor&lt;/dc.contributor.role&gt;
    &lt;dc.date&gt;2013-05-07&lt;/dc.date&gt;
    &lt;dc.format&gt;30 pages&lt;/dc.format&gt;
    &lt;dc.format&gt;545709 bytes&lt;/dc.format&gt;
    &lt;dc.contributor&gt;Jane Smith&lt;/dc.contributor&gt;
    &lt;dc.contributor.role&gt;Committee Member&lt;/dc.contributor.role&gt;
  &lt;/generic_etd&gt;
  </code></pre>
  
  <p>Which I would like to transformed into the following using xslt 1.0:</p>
  
  <pre><code>&lt;etd_ms&gt;
    &lt;etd_ms:contributor&gt;NSERC&lt;/etd_ms:contributor&gt;
    &lt;etd_ms:creator&gt;gradstudent&lt;/etd_ms:creator&gt;
    &lt;etd_ms:contributor role="Advisor"&gt;John Smith&lt;/etd_ms:contributor&gt;
    &lt;etd_ms:date&gt;2013-05-07&lt;/etd_ms:date&gt;
    &lt;etd_ms:format&gt;30 pages&lt;/etd_ms:format&gt;
    &lt;etd_ms:format&gt;545709 bytes&lt;/etd_ms:format&gt;
    &lt;etd_ms:contributor role="Committee Member"&gt;Jane Smith&lt;/etd_ms:contributor&gt;
  &lt;/etd_ms&gt;
  </code></pre>
  
  <p>I can do the etd_ms substitution but what I am having difficulty with is inserting the contributor.role line as an attribute of the contributor line. I am new at xslt transforms so this has me stumped. Any suggestions?</p>
  
  <p>Here is the code so far (I have left out the beginning and end tags for brevity. I also I want to thank Navin Rawat who provided this much more succinct version of code then what I originally had):</p>
  
  <pre><code>&lt;xsl:output method="xml" indent="yes" encoding="UTF-8"/&gt;
  &lt;xsl:strip-space elements="*"/&gt;
  
  &lt;xsl:template match="node()|@*"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:copy-of select="node()|@*"/&gt;
      &lt;/xsl:copy&gt;
  
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="*"&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="name()='generic_etd'"&gt;
              &lt;etd_ms:thesis&gt;
                  &lt;xsl:apply-templates/&gt;
              &lt;/etd_ms:thesis&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
              &lt;xsl:variable name="newtag" select="concat('etd_ms:',substring-after(name(),'.'))"/&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test="contains($newtag, '.')"&gt;
                      &lt;xsl:element name="{substring-before($newtag,'.')}"&gt;
                          &lt;xsl:apply-templates/&gt;
                      &lt;/xsl:element&gt;
                  &lt;/xsl:when&gt;
                  &lt;xsl:otherwise&gt;
                      &lt;xsl:element name="{$newtag}"&gt;
                          &lt;xsl:apply-templates/&gt;
                      &lt;/xsl:element&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
          &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Thanks.</p>