2012-09-18 2 views
0

xml 파일을 통해 반복하고 싶습니다. // Script2 [@time]을 제외하고는 루핑하는 동안 모든 값이 표시됩니다. 다른 위치에 있으므로 직접 선택한 것과 같은 이유가 있습니다./Script2 [@time]xpath를 사용하여 xslt에서 루핑

<table class="table_styling3"> 
<tr><th>Name</th><th>Duration</th><th>Errors</th><th>Actions</th><th>Verifications</th> <th>Traces</th></tr> 
<xsl:for-each select="Report/Scripts/Script1"> 
<tr> 
<td widht="20%"><xsl:value-of select="@File"/></td> 
<td widht="20%"><xsl:value-of select="//Script2[@time]"/></td> 
<td width="10%"><xsl:value-of select="count(Message[@Type='Error'])"/></td> 
<td width="10%"><xsl:value-of select="count(Message[@Type='Action'])"/></td> 
<td width="10%"><xsl:value-of select="count(Message[@Type='Verification'])"/></td> 
<td width="10%"><xsl:value-of select="count(Message[@Type='Trace'])"/></td> 
</tr> 
</xsl:for-each> 
</table> 

내 XML 파일이 비어 표시되는 첫 번째 행과 번째 행 50.000의 시간 0.625 게재 여기

<?xml version="1.0" encoding="utf-8"?> 
<Report App="RIATest" Version="4.7" Project="D:\Projects\Automation\RIATest\Nomura\Nomura.rtp"> 
    <Startup> 
    <Message Time="2012-08-30 15:32:38.578" Type="Info" Message="Launching iexplore.exe &quot;http://mobiuss-dev.operasolutions.com:8080/nomura-test/&quot;"/> 
    <Message Time="2012-08-30 15:32:38.625" Type="Info" Message="Application launched (process id=4108)."/> 
    <Message Time="2012-08-30 15:32:38.625" Type="Info" Message="Waiting for connection from agent..."/> 
    <Message Time="2012-08-30 15:32:46.453" Type="Info" Message="Agent connection accepted. Application id=nomura-ui, index=0"/> 
    </Startup> 
    <Scripts> 
    <Script1 File="Login.rts" Time="2012-08-30 15:32:46.468"> 
    <Message Time="2012-08-30 15:32:46.531" Type="Verification" Line="8" Col="58" Message="Verification passed: SparkApplication(&quot;nomura-ui&quot;)=&gt;visible is equal to true"/> 
    <Message Time="2012-08-30 15:32:46.578" Type="Verification" Line="10" Col="50" Message="Verification passed: FlexForm(&quot;loginForm&quot;)=&gt;visible is equal to true"/> 
    <Message Time="2012-08-30 15:32:46.625" Type="Verification" Line="12" Col="65" Message="Verification passed: FlexLabel(&quot;Username::Username:&quot;)=&gt;text is equal to &quot;Username:&quot;"/> 
    <Message Time="2012-08-30 15:32:46.656" Type="Verification" Line="14" Col="65" Message="Verification passed: FlexLabel(&quot;Password::Password:&quot;)=&gt;text is equal to &quot;Password:&quot;"/> 
    <Message Time="2012-08-30 15:32:46.671" Type="Verification" Line="17" Col="39" Message="Verification passed: comp=&gt;label is equal to &quot;Log In&quot;"/> 
    <Message Time="2012-08-30 15:32:46.703" Type="Verification" Line="18" Col="35" Message="Verification passed: comp=&gt;enabled is equal to true"/> 
    <Message Time="2012-08-30 15:32:46.718" Type="Verification" Line="19" Col="35" Message="Verification passed: comp=&gt;visible is equal to true"/> 
    <Message Time="2012-08-30 15:32:46.734" Type="Verification" Line="22" Col="35" Message="Verification passed: comp=&gt;enabled is equal to true"/> 
    <Message Time="2012-08-30 15:32:46.750" Type="Verification" Line="23" Col="54" Message="Verification passed: comp=&gt;label is equal to &quot;Forgot your password?&quot;"/> 
    <Message Time="2012-08-30 15:32:46.765" Type="Verification" Line="24" Col="36" Message="Verification passed: comp=&gt;selected is equal to false"/> 
    <Message Time="2012-08-30 15:32:46.781" Type="Verification" Line="25" Col="35" Message="Verification passed: comp=&gt;visible is equal to true"/> 
    <Message Time="2012-08-30 15:32:46.796" Type="Verification" Line="28" Col="61" Message="Verification passed: comp=&gt;text is equal to &quot;CORPORATE BOND SPREAD SIGNAL&quot;"/> 
    <Message Time="2012-08-30 15:32:46.812" Type="Verification" Line="29" Col="35" Message="Verification passed: comp=&gt;visible is equal to true"/> 
    <Message Time="2012-08-30 15:32:46.906" Type="Action" Line="32" Col="64" Message="SparkTextInput(&quot;Username::userName&quot;)=&gt;textSelectionChange(0,0)"/> 
    <Message Time="2012-08-30 15:32:47.000" Type="Action" Line="33" Col="63" Message="SparkTextInput(&quot;Username::userName&quot;)=&gt;textInput(&quot;arun.sekar&quot;)"/> 
    <Message Time="2012-08-30 15:32:47.031" Type="Action" Line="35" Col="61" Message="SparkTextInput(&quot;Password::password&quot;)=&gt;textInput(&quot;opera100&quot;)"/> 
    <Message Time="2012-08-30 15:32:47.093" Type="Action" Line="36" Col="32" Message="SparkButton(&quot;Log In&quot;)=&gt;click()"/> 
    </Script> 
    </Scripts> 
    <Results> 
    <Summary scripts="2" time="8.515" errors="2"/> 
    <Script2 name="Login.rts" time="0.625" errors="0"/> 
    <Script2 name="NOM_0002.rts" time="50.000" errors="2" message="Verification failed: comp=&gt;selected is not equal to expected value true, it is actually equal to false"/> 
    </Results> 
    </Report> 

Insted 간다 값 표시되지 테이블의 행과 다른 모든 값이 예상대로 표시됩니다. 당신은 당신의 XSLT에서이 일을하는

+0

예, 실제 파일과 예상 출력은 물론 XML 파일도 확인해야합니다. –

+0

어디서? 난 그냥 "내 XML 파일이 여기에"볼 수 있습니다. –

+0

아, 지금 거기에 있습니다. 그렇다면 실제 결과와 예상 결과는 어떨까요? –

답변

0

..... 그러나

<xsl:value-of select="//Script2[@time]"/> 

,이 속성 @ 시간 @ 2 을 가지고 일 첫 Script2 태그의 텍스트 값을 얻을 것이다 . 나는이 값 @ 시간의 속성을 실제로 원한다고 생각합니다. 이 경우, 당신은 같은 @name을 가지고 발생하여 Script2 태그를 얻을하려는 XSLT보고에서, 그것은 가능하다, ...

<xsl:value-of select="//Script2/@time"/> 

을이 작업을 수행하지만, @ 파일 스크립트 1 태그의 속성.

<xsl:value-of select="//Script2[@name=current()/@File]/@time"/> 

샘플 XML에 적용하면이 스타일 시트

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes"/> 
    <xsl:template match="/"> 
     <table class="table_styling3"> 
     <tr> 
      <th>Name</th> 
      <th>Duration</th> 
      <th>Errors</th> 
      <th>Actions</th> 
      <th>Verifications</th> 
      <th>Traces</th> 
     </tr> 
     <xsl:for-each select="Report/Scripts/Script1"> 
      <tr> 
       <td width="20%"> 
        <xsl:value-of select="@File"/> 
       </td> 
       <td width="20%"> 
        <xsl:value-of select="//Script2[@name=current()/@File]/@time"/> 
       </td> 
       <td width="10%"> 
        <xsl:value-of select="count(Message[@Type='Error'])"/> 
       </td> 
       <td width="10%"> 
        <xsl:value-of select="count(Message[@Type='Action'])"/> 
       </td> 
       <td width="10%"> 
        <xsl:value-of select="count(Message[@Type='Verification'])"/> 
       </td> 
       <td width="10%"> 
        <xsl:value-of select="count(Message[@Type='Trace'])"/> 
       </td> 
      </tr> 
     </xsl:for-each> 
     </table> 
    </xsl:template> 
</xsl:stylesheet> 

을 시도, 다음은이 XSL을 사용하는 것이 더 효율적 것, 실제로 출력

<table class="table_styling3"> 
<tr> 
<th>Name</th> 
<th>Duration</th> 
<th>Errors</th> 
<th>Actions</th> 
<th>Verifications</th> 
<th>Traces</th> 
</tr> 
<tr> 
<td width="20%">Login.rts</td> 
<td width="20%">0.625</td> 
<td width="10%">0</td> 
<td width="10%">4</td> 
<td width="10%">13</td> 
<td width="10%">0</td> 
</tr> 
</table> 

입니다 : 키 여기를 보니 스크립트 2 요소

<xsl:key name="script" match="Script2" use="@name"/> 

대신이 XSLT를 사용해보십시오. 알림 나는 또한 xsl : for-eachxsl : apply-templates으로 대체했으며 이는 종종 XSLT의 '정신'에 더 가깝습니다.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes"/> 
    <xsl:key name="script" match="Script2" use="@name"/> 
    <xsl:template match="/"> 
     <table class="table_styling3"> 
     <tr> 
      <th>Name</th> 
      <th>Duration</th> 
      <th>Errors</th> 
      <th>Actions</th> 
      <th>Verifications</th> 
      <th>Traces</th> 
     </tr> 
     <xsl:apply-templates select="Report/Scripts/Script1"/> 
     </table> 
    </xsl:template> 

    <xsl:template match="Script1"> 
     <tr> 
     <td width="20%"> 
      <xsl:value-of select="@File"/> 
     </td> 
     <td width="20%"> 
      <xsl:value-of select="key('script',@File)/@time"/> 
     </td> 
     <td width="10%"> 
      <xsl:value-of select="count(Message[@Type='Error'])"/> 
     </td> 
     <td width="10%"> 
      <xsl:value-of select="count(Message[@Type='Action'])"/> 
     </td> 
     <td width="10%"> 
      <xsl:value-of select="count(Message[@Type='Verification'])"/> 
     </td> 
     <td width="10%"> 
      <xsl:value-of select="count(Message[@Type='Trace'])"/> 
     </td> 
     </tr> 
    </xsl:template> 
</xsl:stylesheet> 
+0

우수 답변 정확히 무엇을 찾고, 감사합니다 @ 김 C, 내 질문을 이해하고 효율적으로 해결에 시간을 보내고 주셔서 감사합니다. 다시 한번 감사드립니다 :) – Trini