xslt - read last 5 entries from xml in reverse order using xsl -
i want know how modify xsl display last 5 nodes in reverse order xml below.
<?xml version="1.0" standalone="no"?> <?xml-stylesheet type='text/xsl' href='resultxsl.xsl'?> <automation> <run> <client1> <date>25/02/2014</date> <totaltests>23</totaltests> <success>13</success> <failures>10</failures> </client1> <client2> <date>25/02/2014</date> <totaltests>4</totaltests> <success>0</success> <failures>4</failures> </client2> <client3> <date>25/02/2014</date> <totaltests>9</totaltests> <success>3</success> <failures>6</failures> </client3> </run> <run> <client1> <date>26/02/2014</date> <totaltests>23</totaltests> <success>13</success> <failures>10</failures> </client1> <client2> <date>25/02/2014</date> <totaltests>4</totaltests> <success>0</success> <failures>4</failures> </client2> <client3> <date>25/02/2014</date> <totaltests>9</totaltests> <success>3</success> <failures>6</failures> </client3> </run> <run> <client1> <date>27/02/2014</date> <totaltests>23</totaltests> <success>13</success> <failures>10</failures> </client1> <client2> <date>25/02/2014</date> <totaltests>4</totaltests> <success>0</success> <failures>4</failures> </client2> <client3> <date>25/02/2014</date> <totaltests>9</totaltests> <success>3</success> <failures>6</failures> </client3> </run> </automation>
in xsl below getting last 5 nodes xml in correct order. how modify xml nodes in reverse order?
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:tesa="tesa.philips.com"> <xsl:template match="/"> <html> <head> <meta http-equiv="refresh" content="30" /> </head> <body> <hr/> <p> <table border="5" cellpadding="3" cellspacing="0" width="1200"> <tr> <th style="font-weight:bold;background:#a6caf0;width:350px;height:80">date</th> <th style="font-weight:bold;background:#a6caf0;width:350px">total tests</th> <th style="font-weight:bold;background:#a6caf0;width:350px">passed</th> <th style="font-weight:bold;background:#a6caf0;width:350px">failure</th> </tr> <xsl:variable name="vvr_count" select="count(automation/run)"/> <xsl:variable name="vvr_latest10" select="number($vvr_count) - 5"/> <xsl:for-each select="automation/run"> <xsl:if test="$vvr_latest10 <= position()"> <tr> <td class="celltextleft"> <xsl:value-of select="client1/date"/> </td> <td class="celltextleft"> <xsl:value-of select="client1/totaltests"/> </td> <td class="celltextleft"> <xsl:value-of select="client1/success"/> </td> <td class="celltextleft"> <xsl:value-of select="client1/failures"/> </td> </tr> <tr> <td class="celltextleft"> <xsl:value-of select="client2/date"/> </td> <td class="celltextleft"> <xsl:value-of select="client2/totaltests"/> </td> <td class="celltextleft"> <xsl:value-of select="client2/success"/> </td> <td class="celltextleft"> <xsl:value-of select="client2/failures"/> </td> </tr> <tr> <td class="celltextleft"> <xsl:value-of select="client3/date"/> </td> <td class="celltextleft"> <xsl:value-of select="client3/totaltests"/> </td> <td class="celltextleft"> <xsl:value-of select="client3/success"/> </td> <td class="celltextleft"> <xsl:value-of select="client3/failures"/> </td> </tr> <tr style="background:gray"> <td style="height:20"> - </td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </xsl:for-each> </table> </p> </body> </html>
you can add
<xsl:sort select="position()" order="descending" data-type="number"/>
as first child of for-each
reverse processing order. if need change "last five" test because want process first 5 nodes in reverse-order list. alternatively might make more sense move "last five" logic predicate on for-each
select expression instead of using if
:
<xsl:for-each select="(automation/run)[position() > last()-5]"> <xsl:sort select="position()" order="descending" data-type="number"/>
this approach work in xslt 1.0 2.0 (you've tagged question 2.0 current stylesheet version="1.0"
it's not clear need).
Comments
Post a Comment