XSLT:想要对相似的输出值进行分组并赋予它们相关性 headers
XSLT: wanting to group similar output values and give them relevant headers
我是 XML 和 XSLT 的新手,非常感谢任何指导。我无法通过自己的研究解决我的问题。
我正在使用的工具:我正在使用 VSTS 的增强型查询导出扩展。这允许您编写 XML 文档以您想要的格式导出您的工作项目。
目标: 我希望我的输出能够按工作项类型对工作项进行分组,并为这些分组的工作类型赋予特定的 headers。例如:
修复:
我们已修复的错误
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>
试图 post 作为评论,但格式很糟糕,所以我将 post 作为答案。
您还可以设置 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 分组,这就是我正在寻找的解决方案。感谢大家的指点,帮助这个菜鸟!当格式如下时,代码现在可以工作(我已经添加了一些额外的格式):
<?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>
我是 XML 和 XSLT 的新手,非常感谢任何指导。我无法通过自己的研究解决我的问题。
我正在使用的工具:我正在使用 VSTS 的增强型查询导出扩展。这允许您编写 XML 文档以您想要的格式导出您的工作项目。
目标: 我希望我的输出能够按工作项类型对工作项进行分组,并为这些分组的工作类型赋予特定的 headers。例如:
修复:
我们已修复的错误
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>
试图 post 作为评论,但格式很糟糕,所以我将 post 作为答案。
您还可以设置 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 分组,这就是我正在寻找的解决方案。感谢大家的指点,帮助这个菜鸟!当格式如下时,代码现在可以工作(我已经添加了一些额外的格式):
<?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>