tmp.xml:
1<tabel>
2<tr height="20">
3<td class="1">wwwwwwwewref</td>
4<td class="2">ssssssssssss</td>
5<td class="3">sdfsdfsdfgfg</td>
6</tr><tr height="20">
7<td class="1">wwwwwwwewref</td>
8<td class="2">ssssssssssss</td>
9<td class="3">sdfsdfsdfgfg</td>
10</tr><tr height="20">
11<td class="1">wwwwwwwewref</td>
12<td class="2">ssssssssssss</td>
13<td class="3">sdfsdfsdfgfg</td>
14</tr>
15.........
16</tabel>
我想处理上面的table,根据条件给不同的tr加上不同的attribute,比如给第一个添加style="tttt":
1<tr height="20" style="tttt">
2<td class="1">wwwwwwwewref</td>
3<td class="2">ssssssssssss</td>
4<td class="3">sdfsdfsdfgfg</td>
5</tr>
如何写xslt?急!!
---------------------------------------------------------------
1<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"></xsl:output>
3<xsl:template match="/">
4<tabel>
5<xsl:for-each select="tabel/tr">
6<tr>
7<xsl:attribute name="height"><xsl:value-of select="@height"></xsl:value-of></xsl:attribute>
8<xsl:attribute name="style">style<xsl:value-of select="position()"></xsl:value-of></xsl:attribute>
9<xsl:copy-of select="*"></xsl:copy-of>
10</tr>
11</xsl:for-each>
12</tabel>
13</xsl:template>
14</xsl:stylesheet>
---------------------------------------------------------------
"tabel"? not "table"?
1<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2<xsl:template match="node()">
3<xsl:copy>
4<xsl:copy-of select="@*"></xsl:copy-of>
5<xsl:apply-templates select="node()"></xsl:apply-templates>
6</xsl:copy>
7</xsl:template>
8<xsl:template match="tr">
9<xsl:copy>
10<xsl:copy-of select="@*"></xsl:copy-of>
11<xsl:choose>
12<xsl:when test="position() = 1">
13<xsl:attribute name="style">color:red</xsl:attribute>
14</xsl:when>
15<xsl:when test="position() = 2">
16<xsl:attribute name="style">color:green</xsl:attribute>
17</xsl:when>
18<xsl:otherwise>
19</xsl:otherwise>
20</xsl:choose>
21<xsl:apply-templates select="node()"></xsl:apply-templates>
22</xsl:copy>
23</xsl:template>
24</xsl:stylesheet>