Last active
December 18, 2015 02:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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