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!!!
<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!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<table>
<xsl:for-each select='DIRECTOR'>
<tr>
<xsl:attribute name="id"><xsl:value-of select="LEVEL"/></xsl:attr ibute>
<td><xsl:value-of select="LEVEL"/></td>
<td>
<xsl:value-of select='NAME'/>
</td>
</tr>
</xsl:for-each>
</table>
<xsl:for-each select='DIRECTOR'>
<tr>
<xsl:attribute name="id"><xsl:value-of select="LEVEL"/></xsl:attr
<td><xsl:value-of select="LEVEL"/></td>
<td>
<xsl:value-of select='NAME'/>
</td>
</tr>
</xsl:for-each>
</table>
ASKER
This is what I needed! The word 'level' should have been capitalized, but I was swift enough to catch it. Thanks very much.
----
<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>