0

こんにちは、xml と xslt のコードがあります。次の方法で試しましたが、適切な結果が得られませんでした。ここにコードを追加します。

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="XSLTFile1.xslt"?>



 <culture-info current-culture="en-US" current-uiculture="en-US" />
  <test-suite type="Test Project" name="" executed="True" result="Failure" success="False" time="0.290" asserts="0">
 <results>
  <test-suite type="Assembly" name="D:\Samples\DemoNUnitTest\UnitTest\bin\Release\UnitTest.dll" executed="True" result="Failure" success="False" time="0.119" asserts="0">
    <results>
      <test-suite type="Namespace" name="UnitTest" executed="True" result="Failure" success="False" time="0.101" 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.054" 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.019" asserts="0">
            <results>
              <test-case name="UnitTest.NumberValidationTest.ShouldNotValidNumber" executed="True" result="Failure" success="False" time="0.014" 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\UnitTest.dll" executed="True" result="Failure" success="False" time="0.106" asserts="0">
     <results>
      <test-suite type="Namespace" name="UnitTest" executed="True" result="Failure" success="False" time="0.089" asserts="0">
        <results>
          <test-suite type="TestFixture" name="DemoUnitTest" executed="True" result="Success" success="True" time="0.073" asserts="0">
            <results>
              <test-case name="UnitTest.DemoUnitTest.ShouldNotValidNumber" executed="True" result="Success" success="True" time="0.058" asserts="1" />
              <test-case name="UnitTest.DemoUnitTest.ShouldValidNumber" executed="True" result="Success" success="True" time="0.001" asserts="1" />
            </results>
          </test-suite>
          <test-suite type="TestFixture" name="NumberValidationTest" executed="True" result="Failure" success="False" time="0.011" asserts="0">
            <results>
              <test-case name="UnitTest.NumberValidationTest.ShouldNotValidNumber" executed="True" result="Failure" success="False" time="0.007" asserts="1">
                <failure>
                  <message><![CDATA[  Expected: True  But was:  False]]></message>
                  <stack-trace>
                       <![CDATA[at UnitTest.NumberValidationTest.ShouldNotValidNumber()
                     ]]>
                  </stack-trace>
                </failure>
              </test-case>
              <test-case name="UnitTest.NumberValidationTest.ShouldValidNumber" executed="True" result="Success" success="True" time="0.000" asserts="1" />
            </results>
          </test-suite>
          </results>
          </test-suite>
          </results>
        </test-suite>
         </results>
           </test-suite>
       </test-results>

これは私のXSLコードです

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html"/>
 <xsl:template match="/">
 <html>
  <table border="1">
    <!-- The tabel header -->
    <tr>
      <th>Assembly</th>


    </tr>
    <!-- selecting the assamblys -->
    <xsl:call-template name="cal"/>
  </table>
  </html>
  </xsl:template>
  <!-- template for the creation of tabel rows -->
   <xsl:template match="//test-suite[@type='Assembly']" name="cal" >
  <xsl:for-each select="//test-suite[@type='Assembly']">
  <tr>
  <td>
    <xsl:value-of select="@name"/>
  </td>
  <td colspan="0">
    <table>
      <tr>
        <th>TestFixture</th>
      </tr>
      <xsl:for-each select=".//test-suite[@type='TestFixture']">
        <tr>
          <td colspan="0" >
            <xsl:value-of select="@name"/>
          </td>
          <td >
            <table>
              <tr>
                <th>Test Cases</th>
                <th>Result</th>
                <th>Message</th>
              </tr>
              <xsl:for-each select=".//test-case">
                <tr>
                  <td colspan="0">
                    <xsl:value-of select="@name"/>
                  </td>
                  <xsl:choose >
                    <xsl:when test="@result='Success'">
                      <td colspan="0">
                        <xsl:value-of select="@result"/>
                      </td>
                    </xsl:when>
                    <xsl:otherwise >
                      <td bgcolor="red" >
                        <xsl:value-of select="@result"/>
                      </td>
                      <td bgcolor="red">
                        <xsl:value-of select=".//message"/>
                      </td>
                    </xsl:otherwise>

                  </xsl:choose>
                </tr>
              </xsl:for-each>
            </table>
          </td>
        </tr>
      </xsl:for-each>
    </table>
    </td>
    </tr>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

My Result は次のようになります。 結果画像

4

1 に答える 1

1

次の変換でうまくいくはずです。

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:template match="/">
<html>
    <head>
        <title></title>
    </head>
    <body>
        <table>
            <thead>
                <tr>
                    <th>Assemly</th>
                    <th>Test Fixture</th>
                    <th>Test Case</th>
                    <th>Result</th>
                    <th>Message</th>
                </tr>
            </thead>
            <tbody><xsl:for-each select="//test-case">
                <tr>
                    <td><xsl:if test="count(ancestor::test-suite[@type='TestFixture']/preceding-sibling::test-suite[@type='TestFixture'])=0 and count(preceding-sibling::test-case)=0">
                        <xsl:value-of select="ancestor::test-suite[@type='Assembly']/@name" />
                    </xsl:if></td>
                    <td><xsl:if test="count(preceding-sibling::test-case)=0">
                        <xsl:value-of select="ancestor::test-suite[@type='TestFixture']/@name" />
                    </xsl:if></td>
                    <td><xsl:value-of select="@name"/></td>
                    <xsl:choose>
                    <xsl:when test="@result='Success'">
                        <td><xsl:value-of select="@result"/></td>
                        <td></td>
                    </xsl:when>
                    <xsl:otherwise>
                        <td bgcolor="red"><xsl:value-of select="@result"/></td>
                        <td bgcolor="red"><xsl:value-of select=".//message"/></td>
                    </xsl:otherwise>
                    </xsl:choose>
                </tr>
            </xsl:for-each></tbody>
        </table>
    </body>
</html>
    </xsl:template>
</xsl:stylesheet>
于 2013-10-11T23:21:39.203 に答える