xml xslt 如何使用增量变量 [英] xml xslt how to use increment variable

查看:26
本文介绍了xml xslt 如何使用增量变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在xslt中添加增量变量

How to add the increment variable in xslt

我有一张桌子,上面有学生的详细信息,

i have table , with student details,

我想在名字前面加S,

喜欢

1 firstnamJoth LastNameJO LocaitonTexas2 FirstMithul LastNameFig LocationArron

1 firstnamJoth LastNameJO LocaitonTexas 2 FirstMithul LastNameFig LocationArron

在 xslt 中如何做到这一点,我知道,使用 xslt 我们可以做到,我不知道从哪里开始,

In xslt how to do this, i know , with xslt we can do , i dont know where to start,

这是我的 XML 和 XSLT 代码

here is my XML and XSLT code

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="studentlist.xsl"?>
<details>

        <student>
        <a>i want serial no here</a>
        <firstname>SURESH</firstname>
        <lastname>VENKAT</lastname>
        <dob>09-08-1987</dob>
        <location>AVADI</location>
    </student>
    <student>
        <a>i want serial no here</a>
        <firstname>BHARANIKUMAR</firstname>
        <lastname>SRINIVASAN</lastname>
        <dob>09-08-1984</dob>
        <location>VILLIVAKKAM</location>
    </student>



</details>


<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>Student Details</h2>
  <table border="1">
    <tr bgcolor="green">
      <th>FIRSTNAME</th>
      <th>LASTNAME</th>
      <th>DOB</th>
      <th>LOCATION</th>
    </tr>


    <xsl:for-each select="details/student">
    <xsl:sort select="firstname"/>
   <tr>


      <td><xsl:value-of select="firstname"/></td>
      <td><xsl:value-of select="lastname"/></td>
      <td><xsl:value-of select="dob"/></td>
      <td><xsl:value-of select="location"/></td>
     </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

推荐答案

通过您当前的实现,您应该能够使用:

With you current implementation you should be able to use:

<td><xsl:value-of select="position()"/></td>

xsl:for-each 循环中输出一个数字,该数字会随着每次迭代而增加.

within the xsl:for-each loop to output a number which will increase for every iteration.

这篇关于xml xslt 如何使用增量变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆