我正在尝试使用XSLT将TRX文件(XML)转换为HTML,但无法将其转换为 - 完全
这是我的TRX / XML文件的迷你版
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="style.xslt" type="text/xslt"?>
<TestRun id="5d28f629-b34e-428c-9486-46368f6a6211" name="WIN8-VM-X 2014-09-15 10:15:32" runUser="WIN8-VM-X\jd" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Results>
<LoadTestResult executionId="bc475dd2-93d9-4cb5-ac3d-6b088615b8a8" testId="5d7e6f36-158f-4167-aeb3-6f9e5a5d021d" testName="LoadTest1" computerName="WIN8-VM-X" duration="00:02:58.3848158" startTime="2014-09-15T10:15:38.7219789+02:00" endTime="2014-09-15T10:18:37.1067947+02:00" testType="fa4c85ff-1236-4463-b954-3ba2f0eabd95" outcome="Completed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="bc475dd2-93d9-4cb5-ac3d-6b088615b8a8" runId="11" controllerStartTime="2014-09-15T10:15:38.7219789+02:00" runStatus="Stopped" resultsStoreType="Database" resultsRepositoryConnectString="LAs4ogoKlDd+VpAl2ugknpXtkwYcrJ4K4xho6CJjXD1Qv6o/LM9aSaAM4Ac5r6Taj3snulskUGTQzbVVXe9oT7r6RKtPoK7hv4F5g28RXiKSn9lO+5p/Kw==" loadTestDuration="600" loadTestWarmupTime="0" previouslyViewed="false">
<Summary>
<PerformanceCounterResults>
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="true" machineName="WIN8-VM-X" categoryName="LoadTest:Scenario" counterName="User Load" instanceName="_Total" value="1" />
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="true" machineName="WIN8-VM-X" categoryName="LoadTest:Test" counterName="Total Tests" instanceName="_Total" value="10" />
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="LoadTest:Test" counterName="Failed Tests" instanceName="_Total" value="9" />
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="true" machineName="WIN8-VM-X" categoryName="LoadTest:Test" counterName="Tests/Sec" instanceName="_Total" value="0.0560585819" />
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="LoadTest:Test" counterName="Avg. Test Time" instanceName="_Total" value="13.0216" />
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="true" machineName="WIN8-VM-X" categoryName="LoadTest:Request" counterName="Total Requests" instanceName="_Total" value="130" />
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="LoadTest:Request" counterName="Failed Requests" instanceName="_Total" value="18" />
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="true" machineName="WIN8-VM-X" categoryName="LoadTest:Request" counterName="Cached Requests" instanceName="_Total" value="0" />
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="true" machineName="WIN8-VM-X" categoryName="LoadTest:Request" counterName="Requests/Sec" instanceName="_Total" value="0.728761554" />
<PerformanceCounterResult isOverallResultCounter="true" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="LoadTest:Request" counterName="Avg. Response Time" instanceName="_Total" value="0.9909615" />
<PerformanceCounterResult isOverallResultCounter="false" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="Processor" counterName="% Processor Time" instanceName="_Total" value="43.6383438" />
<PerformanceCounterResult isOverallResultCounter="false" higherIsBetter="true" machineName="WIN8-VM-X" categoryName="Memory" counterName="Available MBytes" instanceName="-" value="214" />
<PerformanceCounterResult isOverallResultCounter="false" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="Network Interface" counterName="Bytes Received/sec" instanceName="local area connection* 13" value="0" />
<PerformanceCounterResult isOverallResultCounter="false" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="Network Interface" counterName="Bytes Received/sec" instanceName="intel[r] 82574l gigabit network connection" value="5012.82275" />
<PerformanceCounterResult isOverallResultCounter="false" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="Network Interface" counterName="Bytes Received/sec" instanceName="isatap.localdomain" value="0" />
<PerformanceCounterResult isOverallResultCounter="false" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="Network Interface" counterName="Bytes Sent/sec" instanceName="local area connection* 13" value="6.840497" />
<PerformanceCounterResult isOverallResultCounter="false" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="Network Interface" counterName="Bytes Sent/sec" instanceName="intel[r] 82574l gigabit network connection" value="1746.74634" />
<PerformanceCounterResult isOverallResultCounter="false" higherIsBetter="false" machineName="WIN8-VM-X" categoryName="Network Interface" counterName="Bytes Sent/sec" instanceName="isatap.localdomain" value="0" />
</PerformanceCounterResults>
<TestSummaries>
<TestSummary scenarioName="Scenario1" testName="Testing" totalTests="10" testsFailed="9" averageDuration="13021" />
</TestSummaries>
<TransactionSummaries>
<TransactionSummary scenarioName="Scenario1" testName="Testing" transactionName="Testing.TestingCoded" transactionCount="10" elapsedTime="6772" responseTime="6772" />
<TransactionSummary scenarioName="Scenario1" testName="Testing" transactionName="Testing.TestingPartTwo" transactionCount="10" elapsedTime="6109" responseTime="6109" />
</TransactionSummaries>
</Summary>
</LoadTestResult>
</Results>
</TestRun>
这是我的XSLT文件
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes" />
<xsl:template match="/TestRun/Results">
<html>
<head>
<title>Test Results</title>
</head>
<body>
<table>
<xsl:for-each select="/LoadTestResult/Summary/PerformanceCounterResults/PerformanceCounterResult">
<tr>
<td>
<xsl:value-of select="@counterName" />
</td>
<td>
<xsl:value-of select="@value" />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
有人能发现XSLT中的错误吗?
答案 0 :(得分:2)
问题在于命名空间。您的XML在开始时看起来像这样......
<TestRun xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" ....
这意味着TestRun
元素及其所有后代属于该命名空间。但是,XSLT中没有命名空间的迹象。因此,当你这样做时......
<xsl:template match="/TestRun/Results">
查找没有命名空间的元素,这些元素与命名空间中的元素不同。因此匹配不匹配。
解决方案是在XSLT中声明名称空间,并在匹配表达式中为所有相关元素添加前缀。
试试这个XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:tt="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<xsl:output method="html" indent="yes" />
<xsl:template match="/tt:TestRun/tt:Results">
<html>
<head>
<title>Test Results</title>
</head>
<body>
<table>
<xsl:for-each select="tt:LoadTestResult/tt:Summary/tt:PerformanceCounterResults/tt:PerformanceCounterResult">
<tr>
<td>
<xsl:value-of select="@counterName" />
</td>
<td>
<xsl:value-of select="@value" />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
另请注意,xsl:for-each
出现了错误。你这样做了......
但是最初的/
表示文档节点,因此它会查找名为LoadTestResult
的根元素。您需要删除/
以使其成为相对表达式。