How to sum duration time in the XSLT expressed in 'timespan' format

lilkill12

New Member
In this code challenge I have to create an XSLT transformation that will sum iteration duration time for all TestResut nodes. In few words how long took the TestResults run.\[code\] <TestResults> <TestResult> <Iteration duration="00:00:02.6312623" /> <Iteration duration="00:01:03.5725194" /> <Iteration duration="00:00:07.5725194" /> </TestResult> <TestResult> <Iteration duration="00:00:04.6312623" /> <Iteration duration="00:01:03.6777194" /> <Iteration duration="00:02:07.5723194" /> </TestResult> </TestResults>\[/code\]Sum cannot be done directly on the TestResults/TestResult/Iteration/@duration xpath but instead convert in ticks that represent time is required here, and I am asking: what is the best practice to sum all durations avoiding at the same time multiple conversions?\[code\] <?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="xml" indent="yes"/> <xsl:template match="/"> <xsl:variable name="TotalDuration" select="sum(TestResults/TestResult/Iteration/@duration)"/> <Summary> <Duration> <xsl:value-of select="$TotalDuration"/> </Duration> </Summary> </xsl:template> </xsl:stylesheet>\[/code\]
 
Back
Top