现有XML:
"<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="summary1.xslt"?>
<SYSTEM>
<XMLfile name="Filename of current XML file">sample1.xml</XMLfile>
<TestInstance0>
<LogFile>summary1.log</LogFile>
<TSVFile/>
<TesterID>Me</TesterID>
<Station>DEV01</Station>
<ReleaseVersion>Rel_I02</ReleaseVersion>
<StartTime name="Test Execution Start Date and Time YYYYMMDD:HHmmss">20161221:163642</StartTime>
<EndTime name="Test Execution End Date and Time YYYYMMDD:HHmmss">20161221:174409</EndTime>
<TotalTime name="Test Execution Total Time HH:mm:ss">1:07:27</TotalTime>
<AutoTime name="Test Automation Total Time HH:mm:ss">1:07:27</AutoTime>
<IdleTime name="Test Idle/Wait Total Time HH:mm:ss">0:00:00</IdleTime>
<Status name="Test Execution Status. Use IMCOMPLETE,PASS,FAIL">FAIL</Status>
<TestList>
<Test1>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:163643</StartTime>
<TotalTime name="Total test time in seconds">0</TotalTime>
<AutoTime name="Total automation time in seconds">0</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test1>
<Test2>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:163643</StartTime>
<TotalTime name="Total test time in seconds">940</TotalTime>
<AutoTime name="Total automation time in seconds">940</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test2>
<Test3>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:165223</StartTime>
<TotalTime name="Total test time in seconds">488</TotalTime>
<AutoTime name="Total automation time in seconds">488</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test3>
<Test4>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:170031</StartTime>
<TotalTime name="Total test time in seconds">1067</TotalTime>
<AutoTime name="Total automation time in seconds">47</AutoTime>
<IdleTime name="Total idle/wait time in seconds">1020</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test4>
<Test5>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:171818</StartTime>
<TotalTime name="Total test time in seconds">1551</TotalTime>
<AutoTime name="Total automation time in seconds">1551</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">FAIL</TestResult>
<FailDesc name="Description of failure">Failed Test5</FailDesc>
</Test5>
<Test6>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test6>
<Test7>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test7>
<Test8>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test8>
<Test9>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test9>
<Test10>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test10>
</TestList>
</TestInstance0>
<TestInstance1>
<LogFile>sample1.log</LogFile>
<TSVFile/>
<TesterID>Me</TesterID>
<Station>DEV01</Station>
<ReleaseVersion>Rel_I02</ReleaseVersion>
<StartTime name="Test Execution Start Date and Time YYYYMMDD:HHmmss">20161221:192226</StartTime>
<EndTime name="Test Execution End Date and Time YYYYMMDD:HHmmss">20161221:194931</EndTime>
<TotalTime name="Test Execution Total Time HH:mm:ss">0:27:06</TotalTime>
<AutoTime name="Test Automation Total Time HH:mm:ss">0:27:06</AutoTime>
<IdleTime name="Test Idle/Wait Total Time HH:mm:ss">0:00:00</IdleTime>
<Status name="Test Execution Status. Use IMCOMPLETE,PASS,FAIL">FAIL</Status>
<TestList>
<Test1>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:192226</StartTime>
<TotalTime name="Total test time in seconds">0</TotalTime>
<AutoTime name="Total automation time in seconds">0</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test1>
<Test2>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:192227</StartTime>
<TotalTime name="Total test time in seconds">0</TotalTime>
<AutoTime name="Total automation time in seconds">0</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test2>
<Test3>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:192227</StartTime>
<TotalTime name="Total test time in seconds">73</TotalTime>
<AutoTime name="Total automation time in seconds">73</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test3>
<Test4>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:192340</StartTime>
<TotalTime name="Total test time in seconds">1</TotalTime>
<AutoTime name="Total automation time in seconds">1</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test4>
<Test5>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161221:192341</StartTime>
<TotalTime name="Total test time in seconds">1550</TotalTime>
<AutoTime name="Total automation time in seconds">1550</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">FAIL</TestResult>
<FailDesc name="Description of failure">Failed Test5</FailDesc>
</Test5>
<Test6>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test6>
<Test7>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test7>
<Test8>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test8>
<Test9>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test9>
<Test10>
<StartTime name="Start date and time YYYYMMDD:HHmmss."/>
<TotalTime name="Total test time in seconds"/>
<AutoTime name="Total automation time in seconds"/>
<IdleTime name="Total idle/wait time in seconds"/>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">NOT RUN</TestResult>
<FailDesc name="Description of failure"/>
</Test10>
</TestList>
</TestInstance1>
<TestInstance2>
<LogFile>sample1.log</LogFile>
<TSVFile>sample1.tsv</TSVFile>
<TesterID>Me</TesterID>
<Station>DEV01</Station>
<ReleaseVersion>Rel_I02</ReleaseVersion>
<StartTime name="Test Execution Start Date and Time YYYYMMDD:HHmmss">20161227:003807</StartTime>
<EndTime name="Test Execution End Date and Time YYYYMMDD:HHmmss">20161227:035645</EndTime>
<TotalTime name="Test Execution Total Time HH:mm:ss">3:18:38</TotalTime>
<AutoTime name="Test Automation Total Time HH:mm:ss">3:18:38</AutoTime>
<IdleTime name="Test Idle/Wait Total Time HH:mm:ss">0:00:00</IdleTime>
<Status name="Test Execution Status. Use IMCOMPLETE,PASS,FAIL">PASS</Status>
<TestList>
<Test1>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:003808</StartTime>
<TotalTime name="Total test time in seconds">0</TotalTime>
<AutoTime name="Total automation time in seconds">0</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test1>
<Test2>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:003809</StartTime>
<TotalTime name="Total test time in seconds">0</TotalTime>
<AutoTime name="Total automation time in seconds">0</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test2>
<Test3>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:003809</StartTime>
<TotalTime name="Total test time in seconds">89</TotalTime>
<AutoTime name="Total automation time in seconds">89</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test3>
<Test4>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:003938</StartTime>
<TotalTime name="Total test time in seconds">496</TotalTime>
<AutoTime name="Total automation time in seconds">16</AutoTime>
<IdleTime name="Total idle/wait time in seconds">480</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test4>
<Test5>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:004754</StartTime>
<TotalTime name="Total test time in seconds">144</TotalTime>
<AutoTime name="Total automation time in seconds">144</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test5>
<Test6>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:005018</StartTime>
<TotalTime name="Total test time in seconds">1</TotalTime>
<AutoTime name="Total automation time in seconds">1</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test6>
<Test7>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:005019</StartTime>
<TotalTime name="Total test time in seconds">40</TotalTime>
<AutoTime name="Total automation time in seconds">40</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test7>
<Test8>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:005059</StartTime>
<TotalTime name="Total test time in seconds">719</TotalTime>
<AutoTime name="Total automation time in seconds">599</AutoTime>
<IdleTime name="Total idle/wait time in seconds">120</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test8>
<Test9>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:010258</StartTime>
<TotalTime name="Total test time in seconds">531</TotalTime>
<AutoTime name="Total automation time in seconds">111</AutoTime>
<IdleTime name="Total idle/wait time in seconds">420</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test9>
<Test10>
<StartTime name="Start date and time YYYYMMDD:HHmmss.">20161227:011149</StartTime>
<TotalTime name="Total test time in seconds">396</TotalTime>
<AutoTime name="Total automation time in seconds">396</AutoTime>
<IdleTime name="Total idle/wait time in seconds">0</IdleTime>
<TestResult name="Use INCOMPLETE PASS FAIL SKIP.">PASS</TestResult>
<FailDesc name="Description of failure">COMPLETE</FailDesc>
</Test10>
</TestList>
</TestInstance2>
</SYSTEM>"
现有XSL:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="keyTestInstanceID" match="*[(contains(name(), 'TestInstance'))]" use="." />
<xsl:key name="instances" match="TotalTime" use="@name"/>
<xsl:key name="testinstances" match="TotalTime" use="@name"/>
<xsl:key name="timeStamps" match="EndTime" use="@name"/>
<xsl:template match="SYSTEM">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<!-- BODY tag variables used to save the page scroll position -->
<BODY onScroll="document.cookie='ypos=' + window.pageYOffset" onLoad="window.scrollTo(0,readCookie('ypos'))">
<H1><xsl:value-of select="XMLfile"/></H1>
<div class="hr"><hr></hr></div>
<div class="hr2"><span>New Test History</span></div>
<xsl:for-each select="./*">
<xsl:if test="starts-with(local-name(), 'TestInstance')">
<xsl:value-of select="[generate-id(.) = generate-id(key('keyTestInstanceID', substring(.,13))[1])]"/>
<p><b><xsl:value-of select="local-name()" /></b></p>
<p><xsl:value-of select="substring(local-name(),13)" /></p>
</xsl:if>
</xsl:for-each>
<div class="hr"><hr></hr></div>
<div class="hr2"><span>Old Test History</span></div>
<xsl:for-each select="./*">
<xsl:if test="starts-with(local-name(), 'TestInstance')">
<p><b><xsl:value-of select="local-name()" /></b></p>
<div id="tit">
<xsl:apply-templates select="."/>
</div>
</xsl:if>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
<!-- Test Instance Template -->
<xsl:template match="*[(contains(name(), 'TestInstance'))]">
<!-- Using "instances" key previously defined, store the total test time (seconds) in a variable named "pSum" -->
<xsl:variable name="pSum"><xsl:value-of select="sum(key('instances', 'Total test time in seconds')[text()])" /></xsl:variable>
<div id="tirh">
<div id="ticl1">
Test Name
</div>
<div id="ticl2">
Total (sec)
</div>
<div id="ticl3">
Auto (sec)
</div>
<div id="ticl4">
Idle (sec)
</div>
<div id="ticl5">
Result
</div>
</div>
<xsl:for-each select="*">
<!-- Test Instance Statistics -->
<xsl:if test="starts-with(local-name(), 'TestList')">
<!-- Using "testinstances" key previously defined, store the total test time (seconds) in a variable named "tSum" -->
<xsl:variable name="tSum"><xsl:value-of select="sum(key('testinstances', 'Total test time in seconds')[text()])" /></xsl:variable>
<xsl:for-each select="*">
<div id="tir">
<div id="ticl1">
<xsl:value-of select="local-name()" />
</div>
<div id="ticl2">
<xsl:value-of select="./TotalTime" />
</div>
<div id="ticl3">
<xsl:value-of select="./AutoTime" />
</div>
<div id="ticl4">
<xsl:value-of select="./IdleTime" />
</div>
<div id="ticl5">
<xsl:value-of select="./TestResult" />
</div>
</div>
</xsl:for-each>
<!-- Test Instance Time -->
<div id="tir">
<div id="ticl1">
<b>Sub Total Test Time </b>(HH:MM:SS)
</div>
<div id="ticl2">
<xsl:if test="not(string-length(../TotalTime))=0">
<b><xsl:value-of select="../TotalTime" /></b>
</xsl:if>
<xsl:if test="(string-length(../TotalTime))=0">
<b><xsl:value-of select="concat(format-number(floor($tSum div 3600),'00'), ':', format-number(floor($tSum mod 3600 div 60),'00'), ':', format-number($tSum mod 60,'00'))"/></b>
</xsl:if>
</div>
<div id="ticl3">
</div>
<div id="ticl4">
</div>
<div id="ticl5">
</div>
</div>
<!-- Total Test Time (reformated from variable $pSum) -->
<div id="tir">
<div id="ticl1">
<b>Total Test Time </b>(HH:MM:SS)
</div>
<div id="ticl2">
<b><xsl:value-of select="concat(format-number(floor($pSum div 3600),'00'), ':', format-number(floor($pSum mod 3600 div 60),'00'), ':', format-number($pSum mod 60,'00'))"/></b>
</div>
<div id="ticl3">
</div>
<div id="ticl4">
</div>
<div id="ticl5">
</div>
</div>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>"
目标: 对于每个TestInstance [#]: 在行中显示所有TotalTime值和TestResult。 将所有TotalTime值相加并显示为Sub Total Test Time(HH:MM:SS)。 每个TestInstance [#]还显示一个运行总计作为总测试时间(HH:MM:SS),其中TestInstance0总计等于子总测试时间。 每个额外的TestInstance [#]与上面相同,但每个新的总测试时间(HH:MM:SS)显示((TestInstance的子总测试时间[N])+(TestInstance的子总测试时间[N-1] ))。
示例:
Old Test History
TestInstance0
...
Sub Total Test Time (HH:MM:SS) 1:07:27
Total Test Time (HH:MM:SS) 1:07:27
TestInstance1
...
Sub Total Test Time (HH:MM:SS) 0:27:06
Total Test Time (HH:MM:SS) 1:34:33
TestInstance2
...
Sub Total Test Time (HH:MM:SS) 3:18:38
Total Test Time (HH:MM:SS) 4:53:11
我正在努力解决如何为子总测试时间和总测试时间分配变量,然后获得单独的子总计和一个运行的总测试时间。 我试图使用类似的例子但没有成功。特别是一个 here
答案 0 :(得分:0)
也许这会对你有所帮助。它使用运行总计创建查找数据。用它来查找运行总计。如果需要,您可以使用此查找数据而不是代码中其他位置的键。
set list