xsl循环输出问题
XML文件:
<note>
<id> 1 </id>
<name> 张朝 </name>
<code> 1111111 </code>
<tel> </tel>
</note>
<note>
<id> 2 </id>
<name> 王三 </name>
<code> 2222222 </code>
<tel> </tel>
</note>
<note>
需要通过XSL输出成HTML文件如下:
<tr>
<td> 1 </td>
<td> 张朝 </td>
<td> 1111111 </td>
<td> <input type= "text " style= "WIDTH: 100%; " id= "tel1 "> </td>
</tr>
<tr>
<td> 2 </td>
<td> 王三 </td>
<td> 2222222 </td>
<td> <input type= "text " style= "WIDTH: 100%; " id= "tel2 "> </td>
</tr>
[解决办法]
<xsl:element name= "input ">
<xsl:attribute name= "type "> text </xsl:attribute name>
<xsl:attribute name= "id "> 似乎有它的内置函数可以调用函数改变ID </xsl:attribute name>
</xsl:element>
[解决办法]
<xsl:element name= "input ">
<xsl:attribute name= "type "> text </xsl:attribute name>
<xsl:attribute name= "id "> txt <xsl:value-of select= "position() "/> </xsl:attribute name>
</xsl:element>
或:
<input type= "text " id= "txt{position()} "/>
[解决办法]
我就写关键代码就是了:用xsl的属性for-each 语句:
xsl文件(foreach.xsl)
...
<xsl:stylesheet version= "1.0 " xmlns:xsl= "http://www.w3.org/TR/WD-xsl ">
...
<xsl:for-each select= "note ">
<TR>
<TD> <xsl:value-of select= "id "> </TD>
<TD> <xsl:value-of select= "name "> </TD>
<TD> <xsl:value-of select= "code "> </TD>
<TD> <xsl:value-of select= "tel "> </TD>
</TR>
</xsl:for-each>
xml文件
<?xml-stylesheet type= "text/xsl " href= "foreach.xsl "?>