[英]XSLT: for-each in for-each not working?
i've a XML file which looks like: 我有一个XML文件,看起来像:
<VersionHistory>
<Release Version="0.0.1" Date="27/1/2011">
<NewFeature>foo</NewFeature>
<BugFix>some text</BugFix>
<BugFix>some text</BugFix>
<BugFix Ticket="12004">some text</BugFix>
</Release>
<Release Version="0.0.2" Date="15/2/2011">
<NewFeature>foobar</NewFeature>
<BugFix>some more text</BugFix>
<BugFix>some more text</BugFix>
<BugFix Ticket="12001">some more text</BugFix>
</Release>
</VersionHistory>
Now my XSLT looks like this: 现在,我的XSLT如下所示:
<xsl:template match="/">
<xsl:for-each select="VersionHistory/Release">
<xsl:sort select="@Version"/>
<ul>
<li>
<h3>New Feature<br/></h3>
<xsl:for-each select="NewFeature">
<ul>
<li>
<xsl:value-of select="NewFeature"/>
</li>
</ul>
</xsl:for-each>
</li>
<h3>
Fixed<br/>
</h3>
<xsl:for-each select="BugFix">
<ul>
<li>
<p>
<xsl:value-of select="BugFix"/>
</p>
</li>
</ul>
</xsl:for-each>
</li>
...
My problem is, that the 2nd for-each which goes through the BugFixes creates the amout of list items the xml contains of this element.. but i dont get the text which is between . 我的问题是,通过BugFixes的第二个for-each会创建xml包含此元素的列表项的列表..但是我没有得到介于之间的文本。 Why?
为什么? How can i fix this?
我怎样才能解决这个问题?
this is not only for BugFix of course.. its for all this elements like BugFix, NewFeature (there are some more.. i haven't list here) 当然,这不仅适用于BugFix。它适用于所有这些元素,例如BugFix,NewFeature(还有更多..我这里没有列出)
greets 招呼
In your for-each
you select NewFeature
, then in the value-of
, you are calling the value of a child-node called NewFeature
: 在
for-each
,选择NewFeature
,然后在value-of
,调用子节点 NewFeature
:
<xsl:for-each select="NewFeature">
<ul>
<li>
<xsl:value-of select="NewFeature"/>
</li>
</ul>
</xsl:for-each>
Since NewFeature
doesn't contain a NewFeature
node, you see nothing. 由于
NewFeature
不包含 NewFeature
节点,因此您什么也看不到。
This would work (selecting the current node in the for-each
loop): 这将起作用(在
for-each
循环中选择当前节点):
<xsl:for-each select="NewFeature">
<ul>
<li>
<xsl:value-of select="."/>
</li>
</ul>
</xsl:for-each>
But a better option would be to use a template (which you should to with all of your for-each
loops): 但是更好的选择是使用模板( 所有
for-each
循环都应使用该模板):
<xsl:template match="NewFeature">
<ul>
<li><xsl:value-of select="."/></li>
</ul>
</xsl:template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.