首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >xlst查询使分组只显示每个select值的一个标头,而不是多个标头

xlst查询使分组只显示每个select值的一个标头,而不是多个标头
EN

Stack Overflow用户
提问于 2014-08-17 18:58:19
回答 1查看 38关注 0票数 0

我有一个xlst查询,它从xml原始数据中返回我想要的所有正确信息,但是,因为它有多个对象,所以它返回每个结果,每个结果都有自己的标题,但是我只想在一开始就返回一个,其他人不能帮助我进行分组。这是xlst查询:

代码语言:javascript
运行
复制
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="CMDBSet">
<table border="1">
<tr bgcolor="">
<th>display label</th>
<th>root class</th>
<th>host servertype</th>
<th>host osreleasetype</th>
<th>host osinstalltype</th>
</tr>
<xsl:for-each select="CMDBObject/Properties">
<tr>
<td><xsl:value-of select="display_label"/></td>
<td><xsl:value-of select="root_class"/></td>
<td><xsl:value-of select="host_servertype"/></td>
<td><xsl:value-of select="host_osrelease"/></td>
<td><xsl:value-of select="host_osinstalltype"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

以及xml原始数据的片段:

代码语言:javascript
运行
复制
    <?xml version="1.0" encoding="UTF-8"?>
<CMDBTopology>
<Objects>
<CMDBSet>
<name>80df0b42de8f31ac4cb7a30d325ff0c1</name>
<CMDBObject>
<identifier type="nt">80df0b42de8f31ac4cb7a30d325ff0c1</identifier>
<Properties>
<root_class type="STRING">nt</root_class>
<host_servertype type="STRING"></host_servertype>
<host_osrelease type="STRING"></host_osrelease>
<display_label type="STRING">pharsm-s3004</display_label>
<host_osinstalltype type="STRING"></host_osinstalltype>
</Properties>
</CMDBObject>
</CMDBSet>
<CMDBSet>
<name>8305e305bdaf613b50deab1da4ae469c</name>
<CMDBObject>
<identifier type="nt">8305e305bdaf613b50deab1da4ae469c</identifier>
<Properties>
<root_class type="STRING">nt</root_class>
<host_servertype type="STRING"></host_servertype>
<host_osrelease type="STRING">3790</host_osrelease>
<display_label type="STRING">phchbs-si442</display_label>
<host_osinstalltype type="STRING">Server Standard Edition</host_osinstalltype>
</Properties>
</CMDBObject>

我遇到了一些可能的方法

代码语言:javascript
运行
复制
<xsl:key name="keyrootclass" match="diplaylabel" use="rootclass" />
<xsl:key name="keyhostservertype" match="displaylabel" use="hostservertype" />
<xsl:key name="keyhostosreleasetype" match="displaylabel" use="hostosreleasetype" />
<xsl:key name="keyhostservertype" match="displaylabel" use="hostservertype" />

但是,我被困在如何继续前进,就好像我添加了这些行一样,它不会输出任何东西,但是没有这些键名行,我就会得到输出,但是每个cmdbobject有多个标头。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-17 19:28:19

听起来你只需要这样做:

代码语言:javascript
运行
复制
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <tr bgcolor="">
            <th>display label</th>
            <th>root class</th>
            <th>host servertype</th>
            <th>host osreleasetype</th>
            <th>host osinstalltype</th>
          </tr>
          <xsl:apply-templates
             select="CMDBTopology/Objects/CMDBSet/CMDBObject/Properties" />
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Properties">
    <tr>
      <td>
        <xsl:value-of select="display_label"/>
      </td>
      <td>
        <xsl:value-of select="root_class"/>
      </td>
      <td>
        <xsl:value-of select="host_servertype"/>
      </td>
      <td>
        <xsl:value-of select="host_osrelease"/>
      </td>
      <td>
        <xsl:value-of select="host_osinstalltype"/>
      </td>
    </tr>
  </xsl:template>
</xsl:stylesheet>

在您提供的输入上运行时(添加了缺失的标记之后),这将产生以下输出:

代码语言:javascript
运行
复制
<html>
  <body>
    <table border="1">
      <tr bgcolor="">
        <th>display label</th>
        <th>root class</th>
        <th>host servertype</th>
        <th>host osreleasetype</th>
        <th>host osinstalltype</th>
      </tr>
      <tr>
        <td>pharsm-s3004</td>
        <td>nt</td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>phchbs-si442</td>
        <td>nt</td>
        <td></td>
        <td>3790</td>
        <td>Server Standard Edition</td>
      </tr>
    </table>
  </body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25352599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档