Xml 如何在xslt中使用嵌套分支for each
这里有一个使用单循环的工作示例Xml 如何在xslt中使用嵌套分支for each,xml,xslt,Xml,Xslt,这里有一个使用单循环的工作示例 but whether there is away to do that in single loop. thanks in advance. 书 请注意: 第一个模板匹配库 因此,中针对每个的(相对)XPath用于内部元素,即。 thriller/book 在循环之前,您必须“启动”一个表,然后“关闭”它。 也许你在解决方案中忘记了 源代码中包含的最后两个循环的内容为空, 所以他们什么也不做 您能否同时显示您希望输入的输出?非常感谢
but whether there is away to do that in single loop. thanks in advance.
书
请注意:
- 第一个模板匹配
库
- 因此,
的(相对)XPath用于内部元素,即。中针对每个
thriller/book
- 在循环之前,您必须“启动”一个表,然后“关闭”它。 也许你在解决方案中忘记了
- 源代码中包含的最后两个循环的内容为空, 所以他们什么也不做
book
。因此,如果必须打印当前书籍
的单个子元素,请使用选择=“something”
(不带thriller/book
)。如果有多个这样的子元素,您可以对每个使用,或者例如字符串连接
函数。
but whether there is away to do that in single loop. thanks in advance.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="library">
<table>
<xsl:for-each select="thriller/book">
<tr bgcolor="#9acd32">
<td><xsl:value-of select="ISBN"/></td>
<td><xsl:value-of select="title"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="/">
<hmtl>
<head>
<title>Books</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</hmtl>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
</xsl:transform>