Skip to content

Instantly share code, notes, and snippets.

@ysb33r
Last active December 18, 2015 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysb33r/5712855 to your computer and use it in GitHub Desktop.
Save ysb33r/5712855 to your computer and use it in GitHub Desktop.
I do not know if anyone still uses for XSLTUnit (http://xsltunit.org/) for new development, but I recently had the requirement to convert the XML created by this framework to a JUnit XML format so that it can be read by other tools such as JUnit that understands this format.
<?xml version="1.0" encoding="UTF-8"?>
<!-- ============================================================================
(C) Copyright Schalk W. Cronjé 2013
This code snippet is licensed under the Apache License 2.0
See http://www.apache.org/licenses/LICENSE-2.0 for license details
============================================================================ -->
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1"
xmlns:xsltu="http://xsltunit.org/0/"
exclude-result-prefixes="xsltu">
<xsl:output encoding="UTF-8" method="xml" indent="yes"/>
<xsl:param name="TESTSUITENAME"/>
<xsl:param name="HOSTNAME"/>
<xsl:param name="TIMESTAMP"/>
<xsl:template match="/">
<xsl:if test="not($TESTNAME)">
<xsl:message terminate="yes">TESTSUITENAME not specified, please specify an overal testsuite collection name</xsl:message>
</xsl:if>
<xsl:if test="not($HOSTNAME)">
<xsl:message terminate="yes">HOSTNAME not specified, please specify the host this is being executed on</xsl:message>
</xsl:if>
<xsl:if test="not($TIMESTAMP)">
<xsl:message terminate="yes">TIMESTAMP not specified, please specify a xsd:datetime conformant timestamp (%Y-%m-%dT%H:%M:%S%z)</xsl:message>
</xsl:if>
<testsuites>
<xsl:attribute name="errors">0</xsl:attribute>
<xsl:attribute name="failures"><xsl:value-of select="count(//xsltu:assert[@outcome!='passed'])"/></xsl:attribute>
<xsl:attribute name="tests"><xsl:value-of select="count(//xsltu:assert)"/></xsl:attribute>
<xsl:apply-templates select="//xsltu:test"/>
</testsuites>
</xsl:template>
<xsl:template match="xsltu:test">
<testsuite>
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="errors">0</xsl:attribute>
<xsl:attribute name="failures"><xsl:value-of select="count(xsltu:assert[@outcome!='passed'])"/></xsl:attribute>
<xsl:attribute name="tests"><xsl:value-of select="count(xsltu:assert)"/></xsl:attribute>
<xsl:attribute name="package"><xsl:value-of select="$TESTSUITENAME"/></xsl:attribute>
<xsl:attribute name="hostname"><xsl:value-of select="$HOSTNAME"/></xsl:attribute>
<xsl:attribute name="timestamp"><xsl:value-of select="$TIMESTAMP"/></xsl:attribute>
<xsl:apply-templates select="xsltu:assert"/>
</testsuite>
</xsl:template>
<xsl:template match="xsltu:assert">
<testcase>
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:if test="@outcome!='passed'">
<failure><xsl:value-of select="xsltu:message/text()"/></failure>
</xsl:if>
</testcase>
</xsl:template>
</xsl:transform>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment