Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何在xslt中使用嵌套分支for each_Xml_Xslt - Fatal编程技术网

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元素中有另一个元素lyk,它有内部子元素。如果我只想打印一些子元素,我可以在for each as中给出。然后我将使用打印所有子元素。这是否正确?对于每个select=“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>