XSL帮助从单个行上的多个节点打印变量

时间:2012-03-20 18:22:38

标签: xslt

对于XSL(以及XML)来说是非常新的,但我需要逐步使用XML并在xml数据中的每次运行中在一行上打印所需的选择。我遇到的问题是一个选择(时间)与另一个选择在一个不同的节点中。我还不知道我需要做什么,以获得所需的输出。这是我的数据和样式表,如果有人不介意帮助我:

XSL STYLESHEET

<?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>Storage IO</h2>
   <table border="1">
     <tr bgcolor="#9acd32">
       <th>Time</th>
       <th>Reads per Second</th>
       <th>Writes per Second</th>
       <th>KB Read per Second</th>
       <th>KB Written per Second</th>
       <th>Read Cache Hit %</th>
       <th>Write Cache Hit %</th>
       <th>Sequential Read %</th>
       <th>Write Pending Tracks</th>
     </tr>
     <xsl:for-each select="/SymCLI_ML/Statistics/Request_Totals">
     <tr>
       <td><xsl:value-of select="time"/></td>
       <td><xsl:value-of select="r_per_second"/></td>
       <td><xsl:value-of select="w_per_second"/></td>
       <td><xsl:value-of select="kb_r_per_second"/></td>
       <td><xsl:value-of select="kb_w_per_second"/></td>
       <td><xsl:value-of select="r_cache_hit_pct"/></td>
       <td><xsl:value-of select="w_cache_hit_pct"/></td>
       <td><xsl:value-of select="sequential_r_pct"/></td>
       <td><xsl:value-of select="wp_tracks"/></td>
     </tr>
     </xsl:for-each>
   </table>
   </body>
   </html>
 </xsl:template>
 </xsl:stylesheet>

XML文件

<?xml version="1.0" standalone="yes" ?>
<?xml-stylesheet type="text/xsl" href="totals.xsl"?>
<SymCLI_ML>
  <Statistics>
    <time>Mon Mar 19 2012 15:24:53</time>
  </Statistics>
  <Statistics>
    <time>Mon Mar 19 2012 15:25:04</time>
    <Request>
      <dev_name>0052</dev_name>
      <pd_name>Not Visible</pd_name>
      <r_per_second>0</r_per_second>
      <w_per_second>0</w_per_second>
      <kb_r_per_second>0</kb_r_per_second>
      <kb_w_per_second>0</kb_w_per_second>
      <r_cache_hit_pct>N/A</r_cache_hit_pct>
      <w_cache_hit_pct>N/A</w_cache_hit_pct>
      <sequential_r_pct>N/A</sequential_r_pct>
      <wp_tracks>0</wp_tracks>
    </Request>
    <Request>
      <dev_name>1AAF</dev_name>
      <pd_name>Not Visible</pd_name>
      <r_per_second>0</r_per_second>
      <w_per_second>0</w_per_second>
      <kb_r_per_second>0</kb_r_per_second>
      <kb_w_per_second>0</kb_w_per_second>
      <r_cache_hit_pct>N/A</r_cache_hit_pct>
      <w_cache_hit_pct>N/A</w_cache_hit_pct>
      <sequential_r_pct>N/A</sequential_r_pct>
      <wp_tracks>0</wp_tracks>
    </Request>
    <Request>
      <dev_name>1B2F</dev_name>
      <pd_name>Not Visible</pd_name>
      <r_per_second>0</r_per_second>
      <w_per_second>0</w_per_second>
      <kb_r_per_second>0</kb_r_per_second>
      <kb_w_per_second>0</kb_w_per_second>
      <r_cache_hit_pct>N/A</r_cache_hit_pct>
      <w_cache_hit_pct>N/A</w_cache_hit_pct>
      <sequential_r_pct>N/A</sequential_r_pct>
      <wp_tracks>0</wp_tracks>
    </Request>
    <Request_Totals>
      <r_per_second>1032</r_per_second>
      <w_per_second>1309</w_per_second>
      <kb_r_per_second>28003</kb_r_per_second>
      <kb_w_per_second>19347</kb_w_per_second>
      <r_cache_hit_pct>74</r_cache_hit_pct>
      <w_cache_hit_pct>99</w_cache_hit_pct>
      <sequential_r_pct>6</sequential_r_pct>
      <wp_tracks>9994</wp_tracks>
    </Request_Totals>
  </Statistics>
</SymCLI_ML>

1 个答案:

答案 0 :(得分:0)

尝试使用:

<td><xsl:value-of select="../time"/></td>

<td><xsl:value-of select="/*/Statistics[1]/time"/></td>

取决于您尝试检索的<time>值。