0

我尝试在表格中输出这 2 个食谱,但我不能,它只首先显示给我。如何在表格中输出两个食谱

这是我的xml:

<region id="southwest">
        <name>Southwest</name>
        <recipe id="1" author="" kitchen="en" origin="en">  
            <title>Chicken Fiesta Salad</title>
            <type>main</type>
            <difficulty>middle</difficulty>
            <time>90 min.</time>
            <portions>8</portions>
        </recipe>
        <recipe id="2" author="" kitchen="en" origin="en">  
            <title>Cupcakes</title>
            <type>dessert</type>
            <difficulty>hard</difficulty>
            <time>60 min.</time>
            <portions>8</portions>
        </recipe>       
    </region>

蚂蚁这是我的 xsl:

<table border="1">
    <tr>
      <th>Title</th>
      <th>Region</th>
      <th>Type</th>
      <th>Difficulty</th>
      <th>Time</th>
      <th>Portions</th>
    </tr>
<xsl:for-each select="region">
    <tr>
      <td><xsl:value-of select="recipe/title"/></td>
      <td><xsl:value-of select="name"/></td>
      <td><xsl:value-of select="recipe/type"/></td>
      <td><xsl:value-of select="recipe/difficulty"/></td>
      <td><xsl:value-of select="recipe/time"/></td>
      <td><xsl:value-of select="recipe/portions"/></td>
      </tr>
</xsl:for-each>
</table>

任何人都可以帮助我吗?

4

1 回答 1

0

您需要for-each覆盖配方元素而不是区域元素

<xsl:for-each select="region/recipe">

并适当调整您的 xpath 表达式,例如

  <td><xsl:value-of select="title"/></td>
  <td><xsl:value-of select="../name"/></td>
于 2013-02-04T23:27:15.857 回答