Select attribute value of first node of ancestor

592 views Asked by At

Wanted HTML:

<table>
 <thead>
  <tr>
   <th>1</th>
   <th>2</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>a</td>
   <td>b</td>
  </tr>
  <tr>
   <td>
    <table>
     <tr>
      <td>thisWidth</td>
     </tr>
    </table>
   </td>
  </tr>
 </tbody>
</table>

XML:

<row type='header'>
 <column width='150'>1</column>
 <column>2</column>
 <column type='tableintable' />
</row>
<row type='data'>
 <column>a</column>
 <column>b</column>
 <column>thisWidth</column>
</row>

Everything works like I want, I only want to set the width of the <td> element in HTML. This has to be the width of the first XML header column.
Right now I'm using this:

<xsl:attribute name="width"><xsl:value-of select="//row[@type='header']/@width[position() = 1]" /></xsl:attribute>

This doesn't work. How can I select the value of the wanted column?

1

There are 1 answers

1
dfsq On

Try this XPath expression

<xsl:attribute name="width">
    <xsl:value-of select="//row[@type='header']/column[position() = 1]/@width" />
</xsl:attribute>