<xsl:for-each>表</xsl:for-each>

时间:2013-02-04 23:13:18

标签: xslt foreach html-table

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

这是我的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>

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

您需要for-each超过配方元素而不是区域元素

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

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

  <td><xsl:value-of select="title"/></td>
  <td><xsl:value-of select="../name"/></td>