Link to home
Start Free TrialLog in
Avatar of tab13
tab13

asked on

Real Easy One! - XSL define table <tr> tag id based on XML

I have a XML doc with following example data:
<DIRECTOR id='D11'>
   <NAME>BILL GATES</NAME>
   <LEVEL>D11</LEVEL>
</DIRECTOR>
...

Note that the id value and LEVEL are the same.  I did this to help you help me.  I don't care which one you use for the question below.

I want to use the value D11 as the id in a table row:
<table>
    <xsl:for-each select='DIRECTOR'>
    <tr id='D11'>
       <td>
          <xsl:value-of select='NAME'/>
       </td>
    </tr>
    </xsl:for-each>
</table>

Obviously, I don't want to hard code D11.  Is there a function (xml, javascript, whatever) that will extract the value from either the DIRECTOR id or LEVEL values?

The following DOESN'T work but may give you an idea of where I'm going with this:
    <tr id='{DIRECTOR.id}'>
  *OR*
    <tr id='{LEVEL}'>

Thanks in advance!!!
Avatar of sybe
sybe

node
----
<table>
   <xsl:for-each select='DIRECTOR'>
   <tr id='<xsl:value-of select="level"/>'>
      <td>
         <xsl:value-of select='NAME'/>
      </td>
   </tr>
   </xsl:for-each>
</table>


attribute:
----------
<table>
   <xsl:for-each select='DIRECTOR'>
   <tr id='<xsl:value-of select="@level"/>'>
      <td>
         <xsl:value-of select='NAME'/>
      </td>
   </tr>
   </xsl:for-each>
</table>

ASKER CERTIFIED SOLUTION
Avatar of sybe
sybe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<table>
 <xsl:for-each select='DIRECTOR'>
 <tr>
    <xsl:attribute name="id"><xsl:value-of select="LEVEL"/></xsl:attribute>
    <td><xsl:value-of select="LEVEL"/></td>
    <td>
       <xsl:value-of select='NAME'/>
    </td>
 </tr>
 </xsl:for-each>
</table>
Avatar of tab13

ASKER

This is what I needed!  The word 'level' should have been capitalized, but I was swift enough to catch it.  Thanks very much.