我需要循环一个 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>
最佳答案
关于xml - XSL 到 XML 循环问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6290229/