Эта таблица стилей:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:key name="class" match="TestMethod" use="@className"/>
<xsl:key name="result" match="UnitTestResult" use="@testName"/>
<xsl:template match="/">
<table>
<tr>
<td>Test Name</td>
<td>Result</td>
<td>Duration</td>
<td>Passed</td>
<td>Failed</td>
<td>Inconclusive</td>
</tr>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="TestMethod[count(.|key('class',@className)[1])=1]">
<xsl:variable name="result" select="key('result',key('class',@className)/@name)"/>
<tr>
<td colspan="3"><xsl:value-of select="@className"/></td>
<td><xsl:value-of select="count($result[@outcome='Passed'])"/></td>
<td><xsl:value-of select="count($result[@outcome='Failed'])"/></td>
<td><xsl:value-of select="count($result[@outcome='Inconclusive'])"/></td>
</tr>
<xsl:apply-templates select="key('class',@className)" mode="sub"/>
</xsl:template>
<xsl:template match="TestMethod" mode="sub">
<tr>
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="key('result',@name)/@outcome"/></td>
<td>Not in sample</td>
</tr>
</xsl:template>
</xsl:stylesheet>
Результат:
<table>
<tr>
<td>Test Name</td>
<td>Result</td>
<td>Duration</td>
<td>Passed</td>
<td>Failed</td>
<td>Inconclusive</td>
</tr>
<tr>
<td colspan="3">TestProject1.Test.LogonInfoTest, TestProject1.Test</td>
<td>2</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>NullUserIdInConstructor</td>
<td>Passed</td>
<td>Not in sample</td>
</tr>
<tr>
<td>LogonInfoConstructorTest</td>
<td>Passed</td>
<td>Not in sample</td>
</tr>
</table>
Примечание : метод Мюнхена для получения каждого className
(я делал это в template/@match
, но сегодня кажется, что не могу!) И использование набора узлов для key()
второй аргумент.
Редактировать : Я понял! Кажется, я недостаточно разбирался в шаблонах, встроенных шаблонах и приоритетах ...
Редактировать2 : для первого входного документа
<TestRun id="41242257-adae-4e41-b860-f102021e93c8" name="muthuras@SMUTHURAJA2 2010-06-09 10:13:57" runUser="AMERICAS\muthuras" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">
<ResultSummary outcome="Warning">
<Counters total="3" executed="3" passed="3" error="0" failed="0" timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0" notRunnable="0" notExecuted="0" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" />
<RunInfos>
<RunInfo computerName="SMUTHURAJA2" outcome="Warning" timestamp="2010-06-09T10:13:59.6365402-04:00">
<Text>Code coverage instrumentation warning while processing file ClassLibrary1.dll: Warning VSP2013 : Instrumenting this image requires it to run as a 32-bit process. The CLR header flags have been updated to reflect this.</Text>
</RunInfo>
</RunInfos>
</ResultSummary>
<Times creation="2010-06-09T10:13:57.3115402-04:00" queuing="2010-06-09T10:14:00.1315402-04:00" start="2010-06-09T10:14:00.3665402-04:00" finish="2010-06-09T10:14:02.2425402-04:00" />
<TestDefinitions>
<UnitTest name="EmptyUserIdInConstructor" storage="c:\users\muthuras\documents\visual studio 2008\projects\classlibrary1\testproject1.test\bin\debug\testproject1.test.dll" id="eeffb9fe-2a08-9a88-c3c9-3008a9aeeb50">
<Css projectStructure="" iteration="" />
<Owners>
<Owner name="" />
</Owners>
<Execution id="ec93c5dc-afbb-41b6-81a1-157d39286eca" />
<TestMethod codeBase="C:\Users\muthuras\Documents\Visual Studio 2008\Projects\ClassLibrary1\TestProject1.Test\bin\Debug\TestProject1.Test.dll" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="TestProject1.Test.LogonInfoTest, TestProject1.Test" name="EmptyUserIdInConstructor" />
</UnitTest>
<UnitTest name="NullUserIdInConstructor" storage="c:\users\muthuras\documents\visual studio 2008\projects\classlibrary1\testproject1.test\bin\debug\testproject1.test.dll" id="e58f837c-2116-ce69-bf31-1fe6beec73d3">
<Css projectStructure="" iteration="" />
<Owners>
<Owner name="" />
</Owners>
<Execution id="4ef585f1-02e0-4eb3-b291-29fa7b02d9e6" />
<TestMethod codeBase="C:\Users\muthuras\Documents\Visual Studio 2008\Projects\ClassLibrary1\TestProject1.Test\bin\Debug\TestProject1.Test.dll" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="TestProject1.Test.LogonInfoTest, TestProject1.Test" name="NullUserIdInConstructor" />
</UnitTest>
<UnitTest name="LogonInfoConstructorTest" storage="c:\users\muthuras\documents\visual studio 2008\projects\classlibrary1\testproject1.test\bin\debug\testproject1.test.dll" id="b9bbb3b6-cc0b-7f4d-276e-16c52b0814c6">
<Css projectStructure="" iteration="" />
<Owners>
<Owner name="" />
</Owners>
<Execution id="fca1597d-5011-4d16-965b-afaa9d81ee4e" />
<TestMethod codeBase="C:\Users\muthuras\Documents\Visual Studio 2008\Projects\ClassLibrary1\TestProject1.Test\bin\Debug\TestProject1.Test.dll" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="TestProject1.Test.LogonInfoTest, TestProject1.Test" name="LogonInfoConstructorTest" />
</UnitTest>
</TestDefinitions>
<TestLists>
<TestList name="Results Not in a List" id="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
<TestList name="All Loaded Results" id="19431567-8539-422a-85d7-44ee4e166bda" />
</TestLists>
<TestEntries>
<TestEntry testId="b9bbb3b6-cc0b-7f4d-276e-16c52b0814c6" executionId="fca1597d-5011-4d16-965b-afaa9d81ee4e" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
<TestEntry testId="e58f837c-2116-ce69-bf31-1fe6beec73d3" executionId="4ef585f1-02e0-4eb3-b291-29fa7b02d9e6" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
<TestEntry testId="eeffb9fe-2a08-9a88-c3c9-3008a9aeeb50" executionId="ec93c5dc-afbb-41b6-81a1-157d39286eca" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
</TestEntries>
<Results>
<UnitTestResult executionId="fca1597d-5011-4d16-965b-afaa9d81ee4e" testId="b9bbb3b6-cc0b-7f4d-276e-16c52b0814c6" testName="LogonInfoConstructorTest" computerName="SMUTHURAJA2" duration="00:00:00.0234997" startTime="2010-06-09T10:14:00.8325402-04:00" endTime="2010-06-09T10:14:01.3215402-04:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d">
<Output />
</UnitTestResult>
<UnitTestResult executionId="4ef585f1-02e0-4eb3-b291-29fa7b02d9e6" testId="e58f837c-2116-ce69-bf31-1fe6beec73d3" testName="NullUserIdInConstructor" computerName="SMUTHURAJA2" duration="00:00:00.0047344" startTime="2010-06-09T10:14:01.3235402-04:00" endTime="2010-06-09T10:14:01.3305402-04:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d">
<Output />
</UnitTestResult>
<UnitTestResult executionId="ec93c5dc-afbb-41b6-81a1-157d39286eca" testId="eeffb9fe-2a08-9a88-c3c9-3008a9aeeb50" testName="EmptyUserIdInConstructor" computerName="SMUTHURAJA2" duration="00:00:00.0005633" startTime="2010-06-09T10:14:01.3315402-04:00" endTime="2010-06-09T10:14:01.3345402-04:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d">
<Output />
</UnitTestResult>
</Results>
</TestRun>
Вам нужны небольшие изменения. С помощью этой таблицы стилей:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:test="http://microsoft.com/schemas/VisualStudio/TeamTest/2006" exclude-result-prefixes="test">
<xsl:output indent="yes"/>
<xsl:key name="class" match="test:TestMethod" use="@className"/>
<xsl:key name="result" match="test:UnitTestResult" use="@testName"/>
<xsl:template match="text()"/>
<xsl:template match="/">
<table>
<tr>
<td>Test Name</td>
<td>Result</td>
<td>Duration</td>
<td>Passed</td>
<td>Failed</td>
<td>Inconclusive</td>
</tr>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="test:TestMethod[count(.|key('class',@className)[1])=1]">
<xsl:variable name="result" select="key('result',key('class',@className)/@name)"/>
<tr>
<td colspan="3">
<xsl:value-of select="@className"/>
</td>
<td>
<xsl:value-of select="count($result[@outcome='Passed'])"/>
</td>
<td>
<xsl:value-of select="count($result[@outcome='Failed'])"/>
</td>
<td>
<xsl:value-of select="count($result[@outcome='Inconclusive'])"/>
</td>
</tr>
<xsl:apply-templates select="key('class',@className)" mode="sub"/>
</xsl:template>
<xsl:template match="test:TestMethod" mode="sub">
<tr>
<td>
<xsl:value-of select="@name"/>
</td>
<td>
<xsl:value-of select="key('result',@name)/@outcome"/>
</td>
<td>
<xsl:value-of select="key('result',@name)/@duration"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
Вы получите этот результат:
<table>
<tr>
<td>Test Name</td>
<td>Result</td>
<td>Duration</td>
<td>Passed</td>
<td>Failed</td>
<td>Inconclusive</td>
</tr>
<tr>
<td colspan="3">TestProject1.Test.LogonInfoTest, TestProject1.Test</td>
<td>3</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>EmptyUserIdInConstructor</td>
<td>Passed</td>
<td>00:00:00.0005633</td>
</tr>
<tr>
<td>NullUserIdInConstructor</td>
<td>Passed</td>
<td>00:00:00.0047344</td>
</tr>
<tr>
<td>LogonInfoConstructorTest</td>
<td>Passed</td>
<td>00:00:00.0234997</td>
</tr>
</table>
Примечание : использование пространства имен в шаблонах (ваш первый входной документ имеет пространство имен по умолчанию, но не ваш второй образец). Я нашел ваши данные о продолжительности в вашем первом входе. Вы должны отфильтровать текстовые узлы (в вашем первом входе не было ни одного)