我需要循环一个XML文档。那里没问题。
问题来了,当我需要从上一行我刚刚跳过的文本。XSL到XML循环问题
XML将看一些这样的事
<lines>
<line>
<id>1</id>
<text>Some fancy text here 1</text>
</line>
<line>
<id></id>
<text>This I need in the next line with a ID</text>
</line>
<line>
<id></id>
<text>Also need this.</text>
</line>
<line>
<id>4</id>
<text>Here we go</text>
</line>
</lines>
输出XML文件需要这个样子
<output>
<line>
<id>1</id>
<note>Some fancy text here 1</note>
</line>
<line>
<id>4</id>
<note>Here we go</note>
<extra>
<note>This I need in the next line with a ID</note>
<note>Also need this.</note>
</extra>
</line>
</output>
的XSL我有这样的票价是简单的梳理没有ID设置的线。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<output>
<xsl:for-each select="lines/line">
<xsl:if test="id/text() > 0">
<line>
<id>
<xsl:value-of select="id" />
</id>
<note>
<xsl:value-of select="text" />
</note>
</line>
</xsl:if>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
的'的xsl:for-each'是** **不循环。这是你的'select'每个匹配的函数分配。 – Mikaveli 2011-06-09 13:41:08
+1为好问题。 – 2011-06-09 13:55:46