1

XML が次のようになると仮定します。

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
  <finaloutputxml>
    <execresult starttime="01.01.1970 05:30:00" endtime="01.01.1970 05:30:00" duration="263">
      <devicedetails>
        <devicemodel>SCH-R760U</devicemodel>
        <androidversion>4.1.2</androidversion>
        <basebandversion>S:R760.01 K.FK22</basebandversion>
        <kernelversion>3.0.31-1030861-eng root@QBAGENT131 #3 SMP PREEMPT Fri Mar 8 18:49:29 KST 2013</kernelversion>
        <buildnumber>SCH-R760U-eng 4.1.2 JZO54K U1_TEST test-keys</buildnumber>
     </devicedetails>
    <testsummary>
        <categorycount>3</categorycount>
        <totaltc>27</totaltc>
        <passcount>26</passcount>
        <failcount>0</failcount>
        <errorcount>1</errorcount>
    </testsummary>
    <testcategory name="Open" starttime="22.07.2013 12:03:53" duration="6128" count="21.0" errCount="0" failCount="0" passCount="1">
        <testcase name="TC_Open_001" starttime="22.07.2013 12:03:55" endtime="22.07.2013 12:03:55" duration="485">
           <result>pass</result>
           <author>A</author>
           <description>This is TC description</description>
           <priority>High</priority>
           <returntype>String</returntype>
           <precondition>precondition</precondition>
         </testcase>
        <testcase name="TC_Open_002" starttime="22.07.2013 12:03:55" endtime="22.07.2013 12:03:55" duration="485">
           <result>Fail</result>
           <author>B</author>
           <description>This is TC description</description>
           <priority>High</priority>
           <returntype>String</returntype>
           <precondition>precondition</precondition>
         </testcase>
        <testcase name="TC_Open_003" starttime="22.07.2013 12:03:55" endtime="22.07.2013 12:03:55" duration="485">
           <result>pass</result>
           <author>C</author>
           <description>This is TC description</description>
           <priority>High</priority>
           <returntype>String</returntype>
           <precondition>precondition</precondition>
         </testcase>
    </testcategory>

    <testcategory name="Close" starttime="22.07.2013 12:03:53" duration="6128" count="21.0" errCount="0" failCount="0" passCount="1">
        <testcase name="TC_Close_001" starttime="22.07.2013 12:03:55" endtime="22.07.2013 12:03:55" duration="485">
            <result>pass</result>
           <author>D</author>
           <description>This is TC description</description>
           <priority>High</priority>
           <returntype>String</returntype>
           <precondition>precondition</precondition>
         </testcase>
        <testcase name="TC_Close_002" starttime="22.07.2013 12:03:55" endtime="22.07.2013 12:03:55" duration="485">
           <result>pass</result>
           <author>A</author>
           <description>This is TC description</description>
           <priority>High</priority>
           <returntype>String</returntype>
           <precondition>precondition</precondition>
         </testcase>
        <testcase name="TC_Close_003" starttime="22.07.2013 12:03:55" endtime="22.07.2013 12:03:55" duration="485">
           <result>pass</result>
           <author>A</author>
           <description>This is TC description</description>
           <priority>High</priority>
           <returntype>String</returntype>
           <precondition>precondition</precondition>
         </testcase>
    </testcategory>

    <testcategory name="Start" starttime="22.07.2013 12:03:53" duration="6128" count="21.0" errCount="0" failCount="0" passCount="1">
        <testcase name="TC_Start_001" starttime="22.07.2013 12:03:55" endtime="22.07.2013 12:03:55" duration="485">
           <result>pass</result>
           <author>A</author>
           <description>This is TC description</description>
           <priority>High</priority>
           <returntype>String</returntype>
           <precondition>precondition</precondition>
         </testcase>
        <testcase name="TC_Start_002" starttime="22.07.2013 12:03:55" endtime="22.07.2013 12:03:55" duration="485">
           <result>pass</result>
           <author>A</author>
           <description>This is TC description</description>
           <priority>High</priority>
           <returntype>String</returntype>
           <precondition>precondition</precondition>
         </testcase>
        <testcase name="TC_Start_003" starttime="22.07.2013 12:03:55" endtime="22.07.2013 12:03:55" duration="485">
           <result>pass</result>
           <author>A</author>
           <description>This is TC description</description>
           <priority>High</priority>
           <returntype>String</returntype>
           <precondition>precondition</precondition>
         </testcase>
    </testcategory>
</execresult>

出力は次のようになります

カテゴリ 詳細 オープン TC 名 Start_Time End_Time 期間
TC_Open_001 22.07.2013 12:03:55 22.07.2013 12:03:55 485
TC_Open_002 22.07.2013 12:03:57 22.07.2013 12:03:58 499
TC_Open2.001 04:00 22.07.2013 12:04:00 111

                 Close

TC 名 Start_Time End_Time 期間
TC_Close_001 22.07.2013 12:03:55 22.07.2013 12:03:55 485
TC_Close_002 22.07.2013 12:03:57 22.07.2013 12:03:58 499
TC_Close_00703:203.1 22.07.2013 12:04:00 111

                 Start

TC 名 Start_Time End_Time 継続時間
TC_Start_001 22.07.2013 12:03:55 22.07.2013 12:03:55 485
TC_Start_002 22.07.2013 12:03:57 22.07.2013 12:03:58 499
TC_Start_00702:204.21. 22.07.2013 12:04:00 111

私は以下のようにしました

      <?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" indent="yes" version="4.0"
            doctype-public="-//W3C//DTD HTML 4.01//EN"
            doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
      <xsl:template match="/">
     <html>
      <head></head>
      <body>
      <div>
       <div style="font-size: 14pt; font-weight: bold; margin-bottom: 1em; width: 40%;">Test Results</div>
       <xsl:apply-templates select="finaloutputxml/execresult/devicedetails"/>

      <div style="font-size: 14pt; font-weight: bold; margin-bottom: 1em; width: 40%;"></div>
      <xsl:apply-templates select="finaloutputxml/execresult/testsummary"/>

     <div style="font-size: 14pt; font-weight: bold; margin-bottom: 1em; width: 40%;">Category Details</div>
     <xsl:apply-templates select="finaloutputxml/execresult/testcategory"/>

      <div style="font-size: 14pt; font-weight: bold; margin-bottom: 1em; width: 40%;">Testcase Details</div>
     <xsl:apply-templates select="finaloutputxml/execresult/testcategory/testcase"/>
     </div>
   </body>
 </html>
</xsl:template>
    <xsl:template match="devicedetails">
    <table align="left" border="1" style="margin-bottom: 1em;">
        <caption style="font-size: 12pt; background-color: silver; text-align: center; font-weight: bold;">Device Details</caption>
        <tr>
           <th colspan="2">
             <xsl:value-of select="parent::node()/@name"/>
            </th>
         </tr>

        <tr>
           <td>Device Model</td>
            <td>
               <xsl:value-of select="devicemodel"/>
            </td>
        </tr>

        <tr>
           <td>Andriod Version</td>
            <td>
               <xsl:value-of select="androidversion"/>
             </td>
        </tr>

        <tr>
           <td>Baseband Version</td>
            <td>
               <xsl:value-of select="basebandversion"/>
             </td>
        </tr>

        <tr>
            <td>Kernel Version</td>
            <td>
               <xsl:value-of select="kernelversion"/>
             </td>
        </tr>

        <tr>
            <td>Build Number</td>
            <td>
               <xsl:value-of select="buildnumber"/>
             </td>
          </tr>
      </table>
     </xsl:template>

    <xsl:template match="testsummary">
      <table align="left" border="1" style="margin-bottom: 1em; margin-left: 10pt;">
      <caption style="font-size: 12pt; background-color: silver; text-align: center; font-weight: bold;">Test Summary</caption>
       <tr>
         <th colspan="2">
         <xsl:value-of select="parent::node()/@name"/>
         </th>
       </tr>

       <tr>
        <td>Category Count</td>
        <td>
          <xsl:value-of select="categorycount"/>
        </td>
      </tr>

      <tr>
         <td>Total Count</td>
         <td>
            <xsl:value-of select="totaltc"/>
        </td>
      </tr>

       <tr>
         <td>Pass Count</td>
         <td>
          <xsl:value-of select="passcount"/>
         </td>
      </tr>

      <tr>
         <td>Fail Count</td>
         <td>
            <xsl:value-of select="failcount"/>
         </td>
      </tr>

     <tr>
       <td>Error Count</td>
       <td>
         <xsl:value-of select="errorcount"/>
       </td>
    </tr>
  </table>
</xsl:template>

    <xsl:template match="testcategory">
      <table border="1" style="margin-bottom: 1em; width: 40%">
        <caption style="font-size: 12pt; background-color: silver; text-align: center; font-weight: bold;">
         <xsl:value-of select="@name"/>
      </caption>
        <tr>
         <th>Testcase Name</th>
         <th>Start Time</th>
         <th>End Time</th>
         <th>Duration</th>
       </tr>
         <xsl:apply-templates select="testcase"/>
       </table> 
 </xsl:template>

   <xsl:template match="testcase">
      <tr>
         <td>
           <xsl:value-of select="@name"/>
         </td>
         <td>
           <xsl:value-of select="@starttime"/>
        </td>

         <td>
            <xsl:value-of select="@endtime"/>
         </td>

         <td>
             <xsl:value-of select="@duration"/>
         </td>
       </tr>
  </xsl:template> 

    <!--  <xsl:template match="testcase">
      <xsl:template match="finaloutputxml/execresult/testcategory/testcase">
          <table border="1" style="margin-bottom: 1em; width: 40%">
             <caption style="font-size: 12pt; background-color: silver; text-align: center; font-weight: bold;">
               <xsl:value-of select="@name"/>
             </caption>
          <tr>
            <th>Result</th>
            <td> <xsl:value-of select="Result"/> </td>
         </tr>
         <tr>
            <th>Author</th>
            <td> <xsl:value-of select="author"/> </td>
         </tr>
         <tr>
            <th>Description</th>
            <td> <xsl:value-of select="description"/> </td>
         </tr>
         <tr>
            <th>Priority</th>
            <td> <xsl:value-of select="priority"/> </td>
         </tr>
         <tr>
            <th>Return Type</th>
            <td> <xsl:value-of select="returntype"/> </td>
         </tr>
         <tr>
            <th>Precondition</th>
            <td> <xsl:value-of select="precondition"/> </td>
         </tr>
      </table>  
    </xsl:template>
    </xsl:template>  --> 
  </xsl:stylesheet>
4

1 に答える 1

1

行数はセクションごとに異なる可能性があるため、この問題を解決する 1 つの方法は、XML 文書の階層に従って作業を分割することです。Device Details テーブルと Test Summary テーブルは、Test Category テーブルの下に並んで表示されます。

<?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" indent="yes" version="4.0"
                doctype-public="-//W3C//DTD HTML 4.01//EN"
                doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>

    <xsl:variable name="header_style">
        <xsl:text>font-size: 14pt; font-weight: bold; margin-bottom: 1em; width: 40%;</xsl:text>
    </xsl:variable>

    <xsl:variable name="caption_style">
        <xsl:text>font-size: 12pt; background-color: silver; text-align: center; font-weight: bold;</xsl:text>
    </xsl:variable>

    <xsl:variable name="detail_table_style">
        <xsl:text>margin-right: 5pt; float: left;</xsl:text>
    </xsl:variable>

    <xsl:variable name="div_style">
        <xsl:text>clear: both; margin-bottom: 1em;</xsl:text>
    </xsl:variable>

    <xsl:variable name="summary_table_style">
        <xsl:text>margin-right: 10pt; float: left;</xsl:text>
    </xsl:variable>

    <xsl:variable name="cat_table_style">
        <xsl:text>width: 40%</xsl:text>
    </xsl:variable>

    <xsl:template match="/">
        <html>
            <head></head>
            <body>
                <div style="{$div_style}">
                    <div style="{$header_style}">Category Details</div>
                    <xsl:apply-templates select="finaloutputxml/execresult"/>
                </div>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="execresult">
        <xsl:apply-templates select="testcategory"/>
        <div style="{$div_style}">
            <xsl:apply-templates select="devicedetails"/>
            <xsl:apply-templates select="testsummary"/>
        </div>
    </xsl:template>

    <xsl:template match="testcategory">
        <div style="{$div_style}">
            <table border="1" style="{$cat_table_style}">
                <caption style="{$caption_style}">
                    <xsl:value-of select="@name"/>
                </caption>
                <tr>
                    <th>Testcase Name</th>
                    <th>Start Time</th>
                    <th>End Time</th>
                    <th>Duration</th>
                </tr>
                <xsl:apply-templates select="testcase" mode="summary"/>
            </table>
        </div>
        <div style="{$div_style}">
            <xsl:apply-templates select="testcase" mode="details"/>
        </div>
    </xsl:template>

    <xsl:template match="testcase" mode="summary">
        <tr>
            <td>
                <xsl:value-of select="@name"/>
            </td>
            <td>
                <xsl:value-of select="@starttime"/>
            </td>
            <td>
                <xsl:value-of select="@endtime"/>
            </td>
            <td>
                <xsl:value-of select="@duration"/>
            </td>
        </tr>
    </xsl:template>

    <xsl:template match="testcase" mode="details">       
        <table  border="1" style="{$detail_table_style}">
            <caption style="{$caption_style}">
                <xsl:value-of select="concat(parent::node()/@name, ': ', @name)"/>
            </caption>
            <tr>
                <td>Result</td>
                <td>
                    <xsl:value-of select="result"/>
                </td>
            </tr>
            <tr>
                <td>Author</td>
                <td>
                    <xsl:value-of select="author"/>
                </td>
            </tr>
            <tr>
                <td>Description</td>
                <td>
                    <xsl:value-of select="description"/>
                </td>
            </tr>
            <tr>
                <td>Priority</td>
                <td>
                    <xsl:value-of select="priority"/>
                </td>
            </tr>
            <tr>
                <td>Return Type</td>
                <td>
                    <xsl:value-of select="returntype"/>
                </td>
            </tr>
            <tr>
                <td>Preconditon</td>
                <td>
                    <xsl:value-of select="precondition"/>
                </td>
            </tr>
        </table>
    </xsl:template>

    <xsl:template match="devicedetails">
        <table border="1" style="{$summary_table_style}">
            <caption style="{$caption_style}">Device Details</caption>
            <tr>
                <th colspan="2">
                    <xsl:value-of select="parent::node()/@name"/>
                </th>
            </tr>
            <tr>
                <td>Device Model</td>
                <td>
                    <xsl:value-of select="devicemodel"/>
                </td>
            </tr>
            <tr>
                <td>Andriod Version</td>
                <td>
                    <xsl:value-of select="androidversion"/>
                </td>
            </tr>
            <tr>
                <td>Baseband Version</td>
                <td>
                    <xsl:value-of select="basebandversion"/>
                </td>
            </tr>
            <tr>
                <td>Kernel Version</td>
                <td>
                    <xsl:value-of select="kernelversion"/>
                </td>
            </tr>
            <tr>
                <td>Build Number</td>
                <td>
                    <xsl:value-of select="buildnumber"/>
                </td>
            </tr>
        </table>
    </xsl:template>

    <xsl:template match="testsummary">
        <table border="1" style="{$summary_table_style}">
            <caption style="{$caption_style}">Test Summary</caption>
            <tr>
                <th colspan="2">
                    <xsl:value-of select="parent::node()/@name"/>
                </th>
            </tr>
            <tr>
                <td>Category Count</td>
                <td>
                    <xsl:value-of select="categorycount"/>
                </td>
            </tr>
            <tr>
                <td>Total Count</td>
                <td>
                    <xsl:value-of select="totaltc"/>
                </td>
            </tr>
            <tr>
                <td>Pass Count</td>
                <td>
                    <xsl:value-of select="passcount"/>
                </td>
            </tr>
            <tr>
                <td>Fail Count</td>
                <td>
                    <xsl:value-of select="failcount"/>
                </td>
            </tr>
            <tr>
                <td>Error Count</td>
                <td>
                    <xsl:value-of select="errorcount"/>
                </td>
            </tr>
        </table>
    </xsl:template>

</xsl:stylesheet>
于 2013-07-30T18:23:27.560 に答える