我无法读出我的嵌套for-each循环.出于某种原因,它不会在直接节点下循环.麻烦似乎与tages.My第一循环发生后,我打开表,并通过全表的管理报告和嵌套在它下面的第二点我循环.这工作正常,但是当我在下面嵌套其他节点时,我能够提取值,但不是特定于父节点.这次演习中我的眼睛充满了血丝,有人可以提供一些帮助.提前致谢.
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
你想要实现的目标是错误的:
<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>
Run Code Online (Sandbox Code Playgroud)
每个的第二个与第一个无关.你的第三个也是如此.
不会current()给你当前迭代的节点.
你可以像这样重写你的前两个:
<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>
Run Code Online (Sandbox Code Playgroud)
第三个可以与您当前的设计一起使用.因为current()每个人都是本地的,所以你的第三个人 - 每个人都不知道其他两个人.此外,您的设计似乎使用xslt作为编程语言,这是不可取的.
最后尝试下次提供一些完整/可编译的示例以及目标文档.