XSL tranform for CppUnit to junit & Clocking

Jim Murff
2007-04-12
2013-04-22
  • Jim Murff
    Jim Murff
    2007-04-12

    Hi;
    I am using the timing library to get timing as well as results. I thought I'd post the xsl I use in case someone might need it. I also fixed the ClockedPlugin timing class stuff from 2002 that was for NT. Got to figure where to post it. I made it a standalone project for VS2007 instead of part of the examples.
    -Jim

    <?xml version='1.0' encoding='UTF-8' ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output indent="yes"/>
        <xsl:template match="/">
            <testsuite>
                <xsl:attribute name="errors">
                    <xsl:value-of select="TestRun/Statistics/Errors"/>
                </xsl:attribute>
                <xsl:attribute name="failures">
                    <xsl:value-of select="TestRun/Statistics/Failures"/>
                </xsl:attribute>
                <xsl:attribute name="name">
                    <xsl:choose>
                        <xsl:when test="boolean(TestRun/SuccessfulTests/Test)">
                            <xsl:variable name="testPath" select="TestRun/SuccessfulTests/Test/Name"/>
                            <xsl:value-of select="substring-before($testPath,'::')"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:variable name="testPath" select="TestRun/FailedTests/Test/Name"/>
                            <xsl:value-of select="substring-before($testPath,'::')"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <xsl:attribute name="tests">
                    <xsl:value-of select="TestRun/Statistics/Tests"/>
                </xsl:attribute>
                <xsl:attribute name="time">
                    <xsl:value-of select="TestRun/TimedTestTree/TimedSuite/Time"/>
                </xsl:attribute>
                <xsl:apply-templates select=""/>
            </testsuite>
        </xsl:template>
        <xsl:template match="/TestRun/SuccessfulTests/Test">
            <testcase>
                <xsl:attribute name="classname">
                    <xsl:value-of select="substring-before(Name, '::')"/>
                </xsl:attribute>
                <xsl:attribute name="name">
                    <xsl:value-of select="substring-after(Name, '::')"/>
                </xsl:attribute>
                <xsl:attribute name="time">
                    <xsl:value-of select="Time"/>
                </xsl:attribute>
            </testcase>
        </xsl:template>
        <xsl:template match="/TestRun/FailedTests/FailedTest">
            <time/>
            <testcase>
                <xsl:attribute name="classname">
                    <xsl:value-of select="substring-before(Name, '::')"/>
                </xsl:attribute>
                <xsl:attribute name="name">
                    <xsl:value-of select="substring-after(Name, '::')"/>
                </xsl:attribute>
                <xsl:attribute name="time">
                    <xsl:value-of select="Time"/>
                </xsl:attribute>
                <error>
                    <xsl:attribute name="message">
                        <xsl:value-of select=" normalize-space(Message)"/>
                    </xsl:attribute>
                    <xsl:attribute name="type">
                        <xsl:value-of select="FailureType"/>
                    </xsl:attribute>
                    <xsl:value-of select="Message"/>
    File: <xsl:value-of select="Location/File"/>
    Line: <xsl:value-of select="Location/Line"/> 
    Data Name:<xsl:value-of select="Data/Name"/> 
    Data Value:<xsl:value-of select="Data/Value"/>
                </error>
            </testcase>
        </xsl:template><!-- skip all text -->
        <xsl:template match="text()|@*"/>
    </xsl:stylesheet>