This is my sample input
<table id="1" style="width=100%">
<tr>
<td id="1">
<table id="2" style="width=50%">
<tr>
<td id="2">
</td>
</tr>
</table>
</td>
</tr>
</table>
I am using xslt1.0. when ever the template match ‘td’ is matched, i need to find the corresponding table id value..For example, If the td with id=1 is matched,i want to take style attribute value from table(id=1) and if the td with id=2 is matched,i want to take style attribute value from table(id=2). I have written ancestor::table/@style in my template, but both td are referring the styles of table with id=1.
You were close. Because there can be more than one
tablein theancestoraxis, you need to get the first one like inancestor::table[1]/@style. Of course, if you are absolute sure there is always a chain oftable->tr->td(not optionaltbody) then you could go with @Flack’s answer.