我尝试搜索并使其工作但我失败了。有人可以帮助我获得一个合适的XSL文件,以反向顺序获取XML节点
我的XML文件看起来像这样
<?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>
我需要以相反的顺序打印RUN节点。目前我有XSL以正确的顺序打印它。
<?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:for-each select="Automation/Run">
<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>
答案 0 :(得分:3)
使用
<xsl:for-each select="Automation/Run">
<xsl:sort select="position()" data-type="number" order="descending"/>
<tr>
<td class="cellTextLeft">
<xsl:value-of select="client1/Date"/>
</td>
而不是
<xsl:for-each select="Automation/Run">
<tr>
<td class="cellTextLeft">
<xsl:value-of select="client1/Date"/>
</td>
答案 1 :(得分:2)
试试这个样式表:
<?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:for-each select="Automation/Run">
<xsl:for-each select="*">
<xsl:sort select="name()" order="descending"/>
<tr>
<td class="cellTextLeft">
<xsl:value-of select="current()/descendant::Date"/>
</td>
<td class="cellTextLeft">
<xsl:value-of select="current()/descendant::TotalTests"/>
</td>
<td class="cellTextLeft">
<xsl:value-of select="current()/descendant::Success"/>
</td>
<td class="cellTextLeft">
<xsl:value-of select="current()/descendant::Failures"/>
</td>
</tr>
</xsl:for-each>
<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>
</xsl:template>
</xsl:stylesheet>