开发者

xml xslt how to use increment variable

开发者 https://www.devze.com 2023-01-26 05:23 出处:网络
How to add the increment variable in xslt i have table , with student details, i want to Add S.No front of the Firstname ,

How to add the increment variable in xslt

i have table , with student details,

i want to Add S.No front of the Firstname ,

like

1 firstnamJoth LastNameJO LocaitonTexas 2 FirstMithul LastNameFig LocationArron

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

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 De开发者_StackOverflowtails</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>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消