Q:

xml transformation - add attributes to previous node depending on current node

I've got an ejb-jar.xml that doesn't have an 'id' attribute in the  tag. 
What would be the best way to fix this?  Could XSLT be used for this? 
<session>
  <ejb-name>EJB1</ejb-name>
  <local-home>x.E1LH</local-home>
  <local>x.E1L</local>
  <ejb-class>x.E1EJB</ejb-class>
  <session-type>Stateless</session-type>
  <transaction-type>Container</transaction-type>
</session>

Should be rewritten as:
<session id="EJB1"> <! --ejb-name gets added as an "id" attribute -->
  <ejb-name>EJB1</ejb-name>
  <local-home>x.E1LH</local-home>
  <local>x.E1L</local>
  <ejb-class>x.E1EJB</ejb-class>
  <session-type>Stateless</session-type>
  <transaction-type>Container</transaction-type>
</session>

A:

xslt can certainly do it... but it really depends on what you need to do. 
Something like (untested)
<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="session">
    <session id="{ejb-name}">
        <xsl:apply-templates select="@* | node()"/>
    </session>
</xsl:template>

