【发布时间】:2011-05-23 16:33:52
【问题描述】:
我想根据 XML 中的内容在表中动态创建行。在下面的代码中,我试图创建一个包含 5 列的行(<tr>)。填满5列后,我想新建一行。
根据以下代码,一行只能包含 5 列。如果我在 XML 上应用 XSL,则会显示错误
XSLT 编译错误。第 574 行的“tr”开始标记与“xsl:when”的结束标记不匹配。第 578 行,位置 7。
570:<table>
571: <xsl:for-each select="/alert/account_links/account_links_info">
572: <xsl:choose>
573: <xsl:when test="position() mod 5 = 1">
574: <tr>
575: <td>
576: <xsl:value-of select="account_id"/>
577: </td>
578: </xsl:when>
579: <xsl:when test="position() mod 5 = 0">
580: <td>
581: <xsl:value-of select="account_id"/>
582: </td>
583: </tr>
584: </xsl:when>
585: <xsl:otherwise>
586: <td>
587: <xsl:value-of select="account_id"/>
588: </td>
589: </xsl:otherwise>
590: </xsl:choose>
591: </xsl:for-each>
592: </table>
输入 Xml:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<alert>
<account_links>
<account_links_info>
<account_id>1</account_id>
</account_links_info>
<account_links_info>
<account_id>2</account_id>
</account_links_info>
<account_links_info>
<account_id>3</account_id>
</account_links_info>
<account_links_info>
<account_id>4</account_id>
</account_links_info>
<account_links_info>
<account_id>5</account_id>
</account_links_info>
</account_links>
</alert>
有人可以帮我解决这个问题吗?
【问题讨论】:
-
您的“XML”格式不正确:它在第 577 行结束 td 之后缺少一个结束 tr 元素,并且在第 580 行开始 td 之前缺少一个开始 tr 元素。即便如此,生成的结构不是有效的 XHTML 表。如果您发布了您想要实现的目标的示例(最好是您输入的示例),这将有所帮助。
-
如果没有您的输入和所需输出的样本,没有人可以帮助您。
-
1 2 3 4 5 -
我想知道如何编写 XSL 代码以在 html 表中的上述 xml 中显示帐户 ID,其中每行包含 5 列....
-
请编辑您的帖子以包含输入 XML,不要将其添加为评论。顺便说一句,评论中的 XML 格式不正确。