本文介绍了XSLT中的嵌套for-each循环不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法使此嵌套的for循环正常工作,我想用EP名称和其他详细信息在该行中的EP上打印所有轨道.第一个for-each循环中的所有内容都可以正确显示,但是for-each循环中没有任何内容可以获取曲目.
I cant seem to get this nested for loop to work correctly, I want to print all of the tracks on the EP in the row with the EP name and other details. Everything from the first for-each loop displays correctly but nothing is pulled through for the for-each loop to get the tracks.
这是我的XML
<dalehoward>
<ep>
<name>Letters EP</name>
<year>2012</year>
<label>Static Audio</label>
<image>letters.jpg</image>
<tracks>
<track number="1">
<tname>Letters</tname>
<length>6.35</length>
</track>
<track number="2">
<tname>Later</tname>
<length>7.56</length>
</track>
<track number="3">
<tname>'89 Flava</tname>
<length>7:38</length>
</track>
<track number="4">
<tname>Safe Presentation</tname>
<length>7.55</length>
</track>
</tracks>
</ep>
<ep>
<name>Inner City EP</name>
<year>2012</year>
<label>Lost My Dog</label>
<image>innercity.jpg</image>
<tracks>
<track number="1">
<tname>C'Mon</tname>
<length>7.15</length>
</track>
<track number="2">
<tname>Koppabird</tname>
<length>6.27</length>
</track>
<track number="3">
<tname>Inner City</tname>
<length>8:50</length>
</track>
<track number="4">
<tname>You Can</tname>
<length>8:16</length>
</track>
<tracks>
</ep>
<dalehoward>
这是XSLT
<xsl:variable name="imagefolder" select="'xml/images/'" />
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1" width="100%">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Year</th>
<th style="text-align:left">Label</th>
<th style="text-align:left">Tracks</th>
<th style="text-align:left">Artwork</th>
</tr>
<xsl:for-each select="dalehoward/ep">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="year"/></td>
<td><xsl:value-of select="label"/></td>
<td>testtext<xsl:for-each select="dalehoward/ep/tracks">
<xsl:value-of select="tname"/><br />
<xsl:value-of select="length"/> <br /><br />
</xsl:for-each></td>
<td><img width="150px" height="150px"><xsl:attribute name="src">
<xsl:copy-of select="$imagefolder"/>
<xsl:value-of select="image"/>
</xsl:attribute></img></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
非常感谢您的帮助
推荐答案
外部循环将您置于ep
的上下文中.需要从那里建立内部循环的上下文(或从根开始作为绝对路径)-因此,请更改:
The outer loop puts you in the context of ep
. The context of the inner loop needs to be established from there (or as an absolute path, starting from the root) - so change:
<xsl:for-each select="dalehoward/ep/tracks">
收件人:
<xsl:for-each select="tracks/track">
这篇关于XSLT中的嵌套for-each循环不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!