想要的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>
一切如我所愿,我只想设置
<td>
的宽度HTML 中的元素。这必须是第一个 XML 标题列的宽度。现在我正在使用这个:
<xsl:attribute name="width"><xsl:value-of select="//row[@type='header']/@width[position() = 1]" /></xsl:attribute>
这行不通。如何选择所需列的值?
最佳答案
试试这个 XPath 表达式
<xsl:attribute name="width">
<xsl:value-of select="//row[@type='header']/column[position() = 1]/@width" />
</xsl:attribute>
关于xml - 选择祖先第一个节点的属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27360791/