首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

xsl循环输出有关问题

2012-02-19 
xsl循环输出问题XML文件:noteid 1 /idname 张朝 /namecode 1111111 /codetel/tel/note

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 "?>

热点排行