0

xsltを使用してhtmlテーブルに変換する必要があります。誰も私がそれをするのを手伝ってください。

<?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>

上記の XML コードから、最初の列のアセンブリ リストのようなテーブルとしてフォーマットする必要があります。次の列はテスト フィクスチャ名に対応します。また、既に試した XSLT コードを以下に追加します。

    <?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>
4

1 に答える 1

1

次のようなことができます。

<?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>
于 2013-10-10T09:06:55.733 に答える