2011-12-08 19 views
6

ネストされたfor-eachループを読み込めません。何らかの理由で、直接ノードの下でループしません。問題は、tages.Nyの最初のループは、私はテーブルを開いた後に起こると、私は管理者のレポートのための全体のテーブルをループし、その下に2番目のノードを入れ子に入れているようだ。これはうまくいきますが、追加のノードを下にネストすると、値を取得できますが、親ノードに固有のものはありません。私の目は、このエクササイズからかなりのぼせがあり、誰かが助けてくれるかもしれません。前もって感謝します。ネストされたXML XSL for eachループ

XSL:

<tr bgcolor="9acd32"> 
    <table><th>Data Source Name:</th></table> 
    <table><th><xsl:value-of select="@Value"/> </th></table> 
    </tr> 
    <tr> 
    <xsl:for-each select="*[name()='PartInformation']"> 
     <table bgcolor="#99ff66"><th>Part Information:</th></table> 
     <table bgcolor="#99ff66"><th><xsl:value-of select="@Value"/></th></table>  
    <tr> 
    <xsl:for-each select="*/*[name()='InspPrgInformation']">  
     <table bgcolor="#33ccff"><th>Inspection Program ID:</th></table> 
     <table bgcolor="#33ccff"><th><xsl:value-of select="@Value"/></th></table> 
    <table bgcolor="#33ccff"><th><xsl:value-of select="@NoOfTracefields"/></th></table> 
    </xsl:for-each> 
    </tr> 
    </xsl:for-each> 
    </tr>   
<tr> 
    <xsl:for-each select="*/*/*[name()='AreaInformation']">  
     <table bgcolor="#FFFF99"><th>Area Information:</th></table> 
     <table bgcolor="#FFFF99"><th><xsl:value-of select="@Area"/></th></table> 
     <table bgcolor="#FFFF99"><th><xsl:value-ofselect="@AreaCount"/>   
    </th></table> 
    </xsl:for-each> 
    </tr> 

</xsl:for-each> 
</table> 
</center> 

XML:

<AdminReports xmlns="30/11/2011 09:25:58"> 

    <AdminReport ID="1"> 
    <DataSourceInformation DataSourceID="2" Value="DCS_AERO_KINSTON_DCS350"> 
     <PartInformation PartID="8" Value="WithAreaInfo"> 
     <InspPrgInformation InspPrgID="10" Value="DCS350_Sec15Drill_Pannel1WithInfo"  NoOfTracefields="1">   
      <AreaInformation Area="L3" AreaCount="59"/> 
      <AreaInformation Area="L4" AreaCount="45"/> 
      <AreaInformation Area="LT4" AreaCount="54"/> 
     </InspPrgInformation> 
     </PartInformation> 
     <PartInformation PartID="9" Value="NoAreaInfo"> 
     <InspPrgInformation InspPrgID="9" Value="DCS350_Sec15Trim_Pannel1" NoOfTracefields="0"/> 
     </PartInformation> 
    </DataSourceInformation> 
    </AdminReport> 

    <AdminReport ID="2"> 
    <DataSourceInformation DataSourceID="2" Value="DCS_AERO_KINSTON_DCS350"> 
     <PartInformation PartID="8" Value="NoAreaInfo"> 
     <InspPrgInformation InspPrgID="10" Value="WithInfo" NoOfTracefields="1">   

     </InspPrgInformation> 
     </PartInformation> 
     <PartInformation PartID="9" Value="AreaInfo"> 
     <InspPrgInformation InspPrgID="9" Value="DCS350_Sec15Trim_Pannel1" NoOfTracefields="0"> 
      <AreaInformation Area="L4" AreaCount="75"/> 
      <AreaInformation Area="LT4" AreaCount="4"/> 
     </InspPrgInformation> 
     </PartInformation> 
    </DataSourceInformation> 
    </AdminReport> 
</AdminReports> 

答えて

7

何をやっているが、あなたが達成したい何のため間違っです:

<xsl:for-each select="*[name()='PartInformation']"> 
    <table bgcolor="#99ff66"><th>Part Information:</th></table> 
    <table bgcolor="#99ff66"><th><xsl:value-of select="@Value"/></th></table>  
    <tr> 
    <xsl:for-each select="*/*[name()='InspPrgInformation']">  
     <table bgcolor="#33ccff"><th>Inspection Program ID:</th></table> 
     <table bgcolor="#33ccff"><th><xsl:value-of select="@Value"/></th></table> 
    <table bgcolor="#33ccff"><th><xsl:value-of select="@NoOfTracefields"/></th></table> 
    </xsl:for-each> 
    </tr> 
</xsl:for-each> 

秒それぞれのためのecondは決して最初のものに関連していません。同じことは、あなたの3番目のものと同じです。

current()は、現在反復されているノードを提供しません。

あなたはこのようにのために、それぞれのあなたの最初の2を書き換えることができます:

<tr> 
      <xsl:for-each select="*[name()='PartInformation']"> 
       <tr> 
        <xsl:for-each select="current()/*/InspPrgInformation"> 
         <table bgcolor="#33ccff"> 
          <th>Inspection Program ID:</th> 
         </table> 
         <table bgcolor="#33ccff"> 
          <th> 
           <xsl:value-of select="@Value"/> 
          </th> 
         </table> 
         <table bgcolor="#33ccff"> 
          <th> 
           <xsl:value-of select="@NoOfTracefields"/> 
          </th> 
         </table> 
        </xsl:for-each> 
       </tr> 
      </xsl:for-each> 
     </tr> 

三つ目は、あなたの現在の設計で使用することができます。 current()は各for-eachにローカルなので、3番目のfor-eachは他の2つについては全く分かりません。加えて、あなたのデザインは、xsltを使用してプログラミング言語として使われているようですが、これは方法ではありません。

最後に、対象となる文書だけでなく、完全な/コンパイル可能な例を次に提供してください。

関連する問題