这是一个不是为工件和所有者硬连线的解决方案:
t:\ftemp>type status.xml
<?xml version="1.0" encoding="UTF-8"?>
<results>
<result_header name="cpu.log">
<owner>VJ </owner>
<artifact>cpu </artifact>
<status>PASS</status>
</result_header>
<result_header name="mem.log">
<owner>BG </owner>
<artifact>mem </artifact>
<status>PASS</status>
</result_header>
<result_header name="dma.log">
<owner>VJ </owner>
<artifact>dma </artifact>
<status>PASS</status>
</result_header>
<result_header name="dma0.log">
<owner>VJ </owner>
<artifact>dma </artifact>
<status>PASS</status>
</result_header>
<result_header name="dma1.log">
<owner>VJ </owner>
<artifact>dma </artifact>
<status>FAIL</status>
</result_header>
</results>
结果:
t:\ftemp>call xslt2 status.xml status.xsl
<?xml version="1.0" encoding="UTF-8"?>
<tr>
<th>artifact</th>
<th>Total</th>
<th>Count Pass</th>
<th>Count Fail
</th>
</tr>
<tr>
<td>cpu </td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>dma </td>
<td>3</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>mem </td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>BG </td>
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>VJ </td>
<td>4</td>
<td>3</td>
<td>1</td>
</tr>
样式表:
t:\ftemp>type status.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="results">
<tr>
<th>artifact</th>
<th>Total</th>
<th>Count Pass</th>
<th>Count Fail
</th>
</tr>
<xsl:for-each-group select="result_header" group-by="artifact">
<xsl:sort select="artifact"/>
<xsl:call-template name="bodyRows"/>
</xsl:for-each-group>
<xsl:for-each-group select="result_header" group-by="owner">
<xsl:sort select="owner"/>
<xsl:call-template name="bodyRows"/>
</xsl:for-each-group>
</xsl:template>
<xsl:template name="bodyRows">
<tr>
<td>
<xsl:value-of select="current-grouping-key()"/>
</td>
<td>
<xsl:value-of select="count(current-group())"/>
</td>
<td>
<xsl:value-of select="count(current-group()[status='PASS'])"/>
</td>
<td>
<xsl:value-of select="count(current-group()[status='FAIL'])"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>