Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

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!!!
0
tab13
Asked:
tab13
  • 2
1 Solution
 
sybeCommented:
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>

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


0
 
zzo38Commented:
<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>
0
 
tab13Author Commented:
This is what I needed!  The word 'level' should have been capitalized, but I was swift enough to catch it.  Thanks very much.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now