Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSLT:希望对类似的输出值进行分组,并给它们提供相关的标题_Xml_Xslt_Xslt Grouping - Fatal编程技术网

Xml XSLT:希望对类似的输出值进行分组,并给它们提供相关的标题

Xml XSLT:希望对类似的输出值进行分组,并给它们提供相关的标题,xml,xslt,xslt-grouping,Xml,Xslt,Xslt Grouping,我是XML和XSLT的新手,因此非常感谢您的指导。我无法通过自己的研究来解决我的问题 我正在使用的工具:我正在使用VST的增强查询导出扩展。这允许您编写XML文档,以所需的格式导出工作项 目标:我希望我的输出按工作项类型对工作项进行分组,并为这些分组的工作类型指定标题。例如: 修复: 我们已经修复了错误 TITLE TYPE DESCRIPTION B1 Bug B1info B2 Bug B2info B3 Bug B3info 改进

我是XML和XSLT的新手,因此非常感谢您的指导。我无法通过自己的研究来解决我的问题

我正在使用的工具:我正在使用VST的增强查询导出扩展。这允许您编写XML文档,以所需的格式导出工作项

目标:我希望我的输出按工作项类型对工作项进行分组,并为这些分组的工作类型指定标题。例如:

修复:
我们已经修复了错误

TITLE   TYPE   DESCRIPTION
B1      Bug    B1info
B2      Bug    B2info
B3      Bug    B3info

改进:
我们对当前功能进行了改进

TITLE   TYPE     DESCRIPTION
I1      Backlog  I1info
I2      Backlog  I2info
I3      Backlog  I3info

当前HTML输出示例:
下面是我当前代码输出的图像

当前代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>

<xsl:key name="workitem" match="//workitem" use="System.WorkItemType" />

  <xsl:template match="//workitem">
  <html>
<body>
    <table border="1">
      <tr bgcolor="#9acd32">
      <th>Title</th>
      <th>Type</th>
      <th>Description</th>      
    </tr>
    <xsl:for-each select="key('workitem',System.WorkItemType)">

     <xsl:choose>

      <xsl:when test="System.WorkItemType = 'Bug' ">
              <h1>Fixes</h1>
              <h2>Bugs we've fixed.</h2>
                <tr>
                  <td><xsl:value-of select="System.Title"/></td>
                 <td><xsl:value-of select="System.WorkItemType"/></td>
                 <td><xsl:value-of select="System.Description"/></td>
               </tr>
      </xsl:when>
      <xsl:when test="System.WorkItemType = 'Product Backlog Item' ">
              <h1>Improvements</h1>
              <h2>Improvements we've made to existing functionality.</h2>
                <tr>
                  <td><xsl:value-of select="System.Title"/></td>
                 <td><xsl:value-of select="System.WorkItemType"/></td>
                 <td><xsl:value-of select="System.Description"/></td>
               </tr>
      </xsl:when>
     </xsl:choose>
    </xsl:for-each>
    </table>
  </body>
  </html>
  <xsl:apply-templates select="workitem" />
  </xsl:template>

</xsl:stylesheet>

标题
类型
描述
修复
我们已经修复了错误。
改进
我们对现有功能进行了改进。

试图以评论的形式发布,但格式很糟糕,所以我将以回复的形式发布

您还可以设置2个for循环,并且仅当它与每个workItemType匹配时才进行处理

由于我没有您的XML可供使用,我将把它放在下面的sudo代码中

Output Bug Header

for each workitem
  if workitem is bug
    output workitem
  end if
end for 

Output backlog Header

for each workitem
  if workitem is backlog
    output workitem
  end if
end for

谢谢大家的意见和建议。我查找了/u/tim-c建议的Muenchian分组,这就是我正在寻找的解决方案。我很感谢大家的提示,帮助这个新手!现在,当按照以下格式设置代码时,代码可以正常工作(此后我添加了一些附加格式):


有什么新鲜事吗
与传统的仪表盘或IT工具不同,“明智领导”是一种自助式、灵活的工具,不依赖于IT,使用户能够自行设置和监控自己选择的度量和警报。

为了完成必要的操作,您还应该向XSLT提供XML文件。看起来您可能正在尝试实现某种形式的分组。如果是这样的话,请仔细阅读这篇文章,它向您展示了如何在XSLT1.0中进行分组。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes"/>

  <xsl:key name="wit" match="//workitem" use="System.WorkItemType" />

  <xsl:template match="/*">
    <html>
      <div style="width:600px; margin: 0 auto; margin-top:40px">

        <span class="title">What's New in</span>
        <img class="logo" src="images/app_name.svg" width="252" height="40" alt="" />

        <div class="body_copy">Unlike traditional dashboards or IT tools, Leading Wisely is a self-service, flexible tool that is not IT dependent, enabling users to set and monitor their choice of measure and alerts themselves.</div>

        <xsl:for-each select="//workitem
              [generate-id() = generate-id(key('wit', System.WorkItemType)[1])]">
          <xsl:sort select="System.WorkItemType" />
          <h1>
            <xsl:value-of select="System.WorkItemType" />
          </h1>
          <xsl:for-each select="key('wit', System.WorkItemType)">
            <xsl:sort select="System.Title" />
            <h3>
              <xsl:value-of select="System.Title" />
            </h3>
            <xsl:value-of select="System.Description" />
          </xsl:for-each>
        </xsl:for-each>
      </div>
      </html>
  </xsl:template>
</xsl:stylesheet>