0

I need to convert it to a html table using xslt. any one help me to do that.

<?xml version="1.0" encoding="utf-8" standalone="no"?>

    <test-results name="D:\Samples\DemoNUnitTest\UnitTest\bin\Release\UnitTest.dll" total="7" errors="0" failures="1" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2013-10-09" time="17:17:32">

 <culture-info current-culture="en-US" current-uiculture="en-US" />
 <test-suite type="Test Project" name="" executed="True" result="Failure" success="False" time="1.261" asserts="0">
<results>
  <test-suite type="Assembly" name="D:\Samples\DemoNUnitTest\UnitTest\bin\Release\UnitTest.dll" executed="True" result="Failure" success="False" time="0.118" asserts="0">
    <results>

      <test-suite type="Namespace" name="UnitTest" executed="True" result="Failure" success="False" time="0.099" asserts="0">
        <results>
          <test-suite type="TestFixture" name="DemoUnitTest" executed="True" result="Success" success="True" time="0.075" asserts="0">
            <results>
              <test-case name="UnitTest.DemoUnitTest.ShouldNotValidNumber" executed="True" result="Success" success="True" time="0.053" asserts="1" />
              <test-case name="UnitTest.DemoUnitTest.ShouldValidNumber" executed="True" result="Success" success="True" time="0.000" asserts="1" />

            </results>
          </test-suite>
          <test-suite type="TestFixture" name="NumberValidationTest" executed="True" result="Failure" success="False" time="0.018" asserts="0">
            <results>
              <test-case name="UnitTest.NumberValidationTest.ShouldNotValidNumber" executed="True" result="Failure" success="False" time="0.013" asserts="1">
                <failure>
                  <message>
                    <![CDATA[  Expected: True  But was:  False]]>
                  </message>
                  <stack-trace>
                    <![CDATA[at UnitTest.NumberValidationTest.ShouldNotValidNumber() in d:\Samples\DemoNUnitTest\UnitTest\Class1.cs:line 24]]>
                  </stack-trace>
                </failure>
              </test-case>
              <test-case name="UnitTest.NumberValidationTest.ShouldValidNumber" executed="True" result="Success" success="True" time="0.001" asserts="1" />
            </results>
          </test-suite>
        </results>
      </test-suite>
    </results>
  </test-suite>
  <test-suite type="Assembly" name="D:\Samples\DemoUnitTest\DemoUnitTest.Tests\bin\Release\DemoUnitTest.Tests.dll" executed="True" result="Success" success="True" time="1.074" asserts="0">
    <results>
      <test-suite type="Namespace" name="DemoUnitTest" executed="True" result="Success" success="True" time="1.056" asserts="0">
        <results>
          <test-suite type="Namespace" name="Tests" executed="True" result="Success" success="True" time="1.056" asserts="0">
            <results>
              <test-suite type="Namespace" name="Controllers" executed="True" result="Success" success="True" time="1.055" asserts="0">
                <results>
                  <test-suite type="TestFixture" name="HomeControllerTest" executed="True" result="Success" success="True" time="1.052" asserts="0">
                    <results>
                      <test-case name="DemoUnitTest.Tests.Controllers.HomeControllerTest.About" executed="True" result="Success" success="True" time="0.735" asserts="1" />
                      <test-case name="DemoUnitTest.Tests.Controllers.HomeControllerTest.Contact" executed="True" result="Success" success="True" time="0.003" asserts="1" />
                      <test-case name="DemoUnitTest.Tests.Controllers.HomeControllerTest.Index" executed="True" result="Success" success="True" time="0.299" asserts="1" />
                    </results>
                  </test-suite>
                </results>
              </test-suite>
            </results>
          </test-suite>
        </results>
      </test-suite>
    </results>
  </test-suite>
</results>

From the above XML code, I need to format it as a table like first column Assembly list, in the next column corresponding Test-fixture name. Also I add the XSLT code below which is i Tried already.

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
    <table border="1">
    <!-- The tabel header -->
    <tr>
      <th>Assembly</th>
      <th>TestFixture</th>
    </tr>
    <!-- selecting the assamblys -->
    <xsl:apply-templates select="//test-suite[@type='Assembly']"/>
    </table>
    </html>
    </xsl:template>
    <!-- template for the creation of tabel rows -->
    <xsl:template match="test-suite[@type='Assembly']">
   <tr>
   <td>
    <xsl:value-of select="@name"/>
   </td>
   <td>
    <table>
      <xsl:for-each select="//test-suite[@type='TestFixture']">
      <tr>
        <td>
          <xsl:value-of select="@name"/>
        </td>
      </tr>
      </xsl:for-each>
    </table>
   </td>
   </tr>
     </xsl:template>
    </xsl:stylesheet>
1
  • 1
    Please show your attempts so far. StackOverflow is not meant to be a platform where you can post tasks and let other people do the coding for you. Commented Oct 10, 2013 at 9:23

1 Answer 1

1

You could do something like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="utf-8" indent="yes" omit-xml-     declaration="yes"/>
    <xsl:template match="/">
        <html>
            <table border="1">
                <!-- The tabel header -->
                <tr>
                    <th>Assembly</th>
                    <th>TestFixture</th>
                </tr>
                <!-- selecting the assamblys -->
                <xsl:apply-templates select="//test-suite[@type='Assembly']"/>
            </table>
        </html>
    </xsl:template>
    <!-- template for the creation of tabel rows -->
    <xsl:template match="test-suite[@type='Assembly']">
        <tr>
            <td>here you put the data for the first column</td>
            <td>second column</td>
        </tr>
    </xsl:template>
</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response. While add the second column, the tree structure is varying for one assembly from another assembly. For that I could't write the for-each statement with select root-path. Please have a deep look in my XML code.
Write .//test-suite[@type='TestFixture'] instead of //test-suite[@type='TestFixture'] without the dot you search the whole xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.