XSL使用多个节点属性

时间:2012-03-05 05:30:40

标签: html xml xslt html-table

我对这一切都不熟悉,并尝试了各种路由和变体来将数据输入到我的表中,但我无法获得第二维和第三维节点属性。我显然在属性值选择或模板使用方面出了问题,因为我只重复了每列的第一个属性。

我的XML输入是:

<nodes>
  <node name="Server Dashboard">
    <children>
      <node name="Server Dashboard">
        <dimension name="Performance" status="20" id="10" >null</dimension>
        <dimension name="System" status="10" id="20" >null</dimension>
        <dimension name="Availability" status="30" id="30" >null</dimension>
        <children>
          <node name="SERVER 1">
            <dimension name="Performance" status="20" id="10" >null</dimension>
            <dimension name="System" status="10" id="20" >null</dimension>
            <dimension name="Availability" status="30" id="30" >null</dimension>
            <children>
            </children>
          </node>
          <node name="SERVER 2">
            <dimension name="Performance" status="20" id="10" >null</dimension>
            <dimension name="System" status="10" id="20" >null</dimension>
            <dimension name="Availability" status="30" id="30" >null</dimension>
            <children>
            </children>
          </node>
        </children>
      </node>
    </children>
  </node>
</nodes>

我正在努力获得像

这样的输出
<html>
  <body>
    <table border="1">
      <th>System</th>
      <th>Performance</th>
      <th>Status</th>
      <th>Availability</th>
    </tr>
    <tr> 
      <td>SERVER 1</td>
      <td>20</td>   
      <td>10</td>
      <td>30</td>
    </tr>
    <tr> 
      <td>SERVER 2</td>
      <td>20</td>   
      <td>10</td>
      <td>30</td>
    </tr>
  </table>
</body>
</html>

目前我有xsl几乎让我在那里,但不完全似乎没有在维度节点上循环。

<xsl:template match="/">
<html>
  <body>
    <table border="1">
        <th>System</th>
        <th>Performance</th>
        <th>Status</th>
        <th>Availability</th>
      </tr>
      <xsl:for-each select="nodes/node/children/node/children/node"> 
      <tr> 
        <td><xsl:value-of select="@name"/></td>
        <td><xsl:value-of select="dimension/@Status[//@id='10']"/></td>   
        <td><xsl:value-of select="dimension/@status[//@id='20']"/></td>
        <td><xsl:value-of select="dimension/@status[//@id='30']"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

我的最终目标是用彩色单元格或.gif替换状态编号,但此时宝贝步骤。 任何帮助都感激不尽。

1 个答案:

答案 0 :(得分:1)

尝试以下方法。要点是先按id属性值选择维度,然后选择状态属性值。

<xsl:template match="/">
    <html>
        <body>
            <table border="1">
            <tr> 
                <th>System</th>
                <th>Performance</th>
                <th>Status</th>
                <th>Availability</th>
            </tr>
            <xsl:for-each select="nodes/node/children/node/children/node"> 
            <tr> 
                <td><xsl:value-of select="@name"/></td>
                <td><xsl:value-of select="dimension[@id='10']/@status"/></td>   
                <td><xsl:value-of select="dimension[@id='20']/@status"/></td>
                <td><xsl:value-of select="dimension[@id='30']/@status"/></td>
            </tr>
            </xsl:for-each>
            </table>
        </body>
      </html>
</xsl:template>