I am trying to write an XSL to transform my XML to a JUNIT format jenkins takes (see below)
my xml looks like this: (i have several "Classes" like 'datacenters' or 'network')
<tests>
<Datacenters>
<test_name>Create NFS Data Center</test_name>
<end_time>2011-06-13 01:22:55</end_time>
<iter_num>1</iter_num>
<start_time>2011-06-13 01:22:52</start_time>
<status>Pass</status>
</Datacenters>
<Datacenters>
<test_name>Create NFS Data Center</test_name>
<end_time>2011-06-13 01:22:55</end_time>
<iter_num>1</iter_num>
<start_time>2011-06-13 01:22:52</start_time>
<status>Pass</status>
</Datacenters>
<Network>
<test_name>Network test 1</test_name>
<end_time>2011-06-13 01:22:57</end_time>
<iter_num>1</iter_num>
<start_time>2011-06-13 01:22:52</start_time>
<status>Pass</status>
</Network>
.....
</tests>
i took an XSL from the WebUI plugin and tried altering it, i'm half way there, but it's still tricky. here's what i've done so far:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<testsuites>
<! -- need to change /Datacenters to something else so it will work on all nodes -->
<xsl:variable name="buildName" select="//tests/Datacenters/test_name"/>
<xsl:variable name="numOfTests" select="count(//tests/Datacenters/iter_num)"/>
<xsl:variable name="numOfFail" select="count(//tests/Datacenters/status [.= 'Fail'])" />
<xsl:variable name="numberSkip" select="count(//tests/Datacenters/status [.!='Pass' and .!='Fail'])" />
<testsuite name="QE AUTOMATION TESTS [DATACENTERS]"
tests="{$numberOfTests}" time="0"
failures="{$numberOfFailures}" errors="0"
skipped="{$numberSkipped}">
<xsl:for-each select="//rest/Datacenters">
<xsl:variable name="testName" select="test_name"/>
<xsl:variable name="executionId" select="iter_num"/>
<xsl:variable name="start_time" select="fn:replace(start_time,' ','T')" />
<xsl:variable name="end_time" select="fn:replace(end_time,' ','T')"/>
<xsl:variable name="test_parameters" select="test_parameters"/>
<xsl:variable name="test_positive" select="test_positive"/>
<xsl:variable name="time_diff" select="xs:dateTime($end_time)-xs:dateTime($start_time)"/>
<xsl:variable name="duration_seconds" select="seconds-from-duration($time_diff)"/>
<xsl:variable name="duration_minutes" select="minutes-from-duration($time_diff)"/>
<xsl:variable name="duration_hours" select="hours-from-duration($time_diff)"/>
<xsl:variable name="outcome" select="status"/>
<xsl:variable name="message" select="$buildName"/>
<!--<xsl:variable name="className" select="Data"/> -->
<testcase classname="Datacenters"
name="{$testName}"
time="{$duration_hours*3600 + $duration_minutes*60 + $duration_seconds }">
<xsl:if test="contains($outcome, 'Fail')">
<failure>
test_parameters: <xsl:value-of select="$test_parameters" />
test_positive: <xsl:value-of select="$test_positive" />
</failure>
</xsl:if>
</testcase>
</xsl:for-each>
</testsuite>
</testsuites>
</xsl:template>
</xsl:stylesheet>
what i want to achieve is this xml:
<testsuites xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<testsuite name="Datacenters" tests="2" time="4" failures="0" errors="0" skipped="0">
<testcase classname="Datacenters" name="Create NFS Data Center" time="3"/>
<testcase classname="Datacenters" name="Create ISCSI Data Center" time="1"/>
</testsuite>
<testsuite name="Network" tests="1" time="5" failures="0" errors="0" skipped="0">
<testcase classname="Datacenters" name="Network test 1" time="5"/>
</testsuite>
</testsuites>
but i don't know how to iterate on all the "classes" so instead of hardcoding "Datacenters" i want it to present all the existing children of <tests>