【发布时间】:2018-10-31 08:03:21
【问题描述】:
我在很短的时间内就开始使用 XSL,我必须使用子标签的一部分创建多个 div。所以我有这样的事情:
<Nodes>
<Node>
<Tag>a</Tag>
<Tag>b</Tag>
</Node>
<Node>
<Tag>c</Tag>
</Node>
</Nodes>
我想我可以这样做:
<xsl:for-each select="/Nodes">
<div id="node_{position()}">
<xsl:for-each select="Node">
<xsl:value-of select="Tag" />
</xsl:for-each>
</div>
</xsl:for-each>
而我需要的是:
<div>
a
b
</div>
<div>
c
</div>
但我总是得到两个带有 b c 的 div。取而代之的是第一个带有b,另一个带有c。 我必须枚举标签或类似的东西吗?
编辑:
<ProjectTopology>
<Nodes>
<Node>
<Tag>Section1</Tag>
<Nodes>
<Node>
<Tag>Another section1</Tag>
<Tag>Another section2</Tag>
</Node>
</Nodes>
<Tag>Section2</Tag>
<Nodes>
<Node>
<Tag>Another section3</Tag>
<Tag>Another section4</Tag>
</Node>
</Nodes>
</Node>
</Nodes>
</ProjectTopology>
好的,我现在正在寻找这样的东西:
<div id="section_1">
Another section1
Another section2
</div>
<div id="section_2">
Another section3
Another section4
</div>
【问题讨论】:
-
看到这个问题,你可能不需要用for-each:stackoverflow.com/questions/52851159/…
标签: html xml xslt foreach transformation