2011-12-08 42 views
6

Tôi gặp sự cố khi đọc các vòng lặp lồng nhau của tôi. Đối với một số lý do, nó không lặp lại dưới các nút trực tiếp. Các rắc rối có vẻ là với các vòng lặp đầu tiên.Ty đầu tiên xảy ra sau khi tôi mở bảng, và tôi lặp qua toàn bộ bảng cho các báo cáo quản trị và làm tổ nút thứ hai bên dưới nó. Điều này làm việc tốt, nhưng khi tôi đi làm tổ thêm các nút bên dưới, tôi có thể kéo các giá trị, nhưng không cụ thể cho nút cha. Đôi mắt của tôi là khá nhiều máu từ tập thể dục này, có thể ai đó cho vay một số giúp đỡ. Cảm ơn trước.XSL lồng nhau cho mỗi vòng lặp

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> 

Trả lời

7

Những gì bạn đang làm là sai cho những gì bạn muốn đạt được:

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

Các s econd cho mỗi là không có nghĩa là liên quan đến cái đầu tiên. Cùng đi với thứ ba của bạn cho mỗi người.

Không phải là current() sẽ cung cấp cho bạn nút hiện đang được lặp lại.

Bạn có thể viết lại đầu tiên của bạn hai for-each như thế này:

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

Người thứ ba có thể được sử dụng với thiết kế hiện tại của bạn. Bởi vì current() là địa phương cho mỗi loại cho nên mỗi phần ba của bạn không có ý tưởng gì về hai loại kia. Ngoài ra, thiết kế của bạn dường như đang sử dụng xslt như một ngôn ngữ lập trình mà không phải là cách để đi.

Cuối cùng, hãy cố gắng cung cấp một số ví dụ hoàn chỉnh/có thể biên dịch vào lần tới cũng như tài liệu đích của bạn.

Các vấn đề liên quan