【发布时间】:2018-08-10 01:57:52
【问题描述】:
我正在尝试从 XML 创建一个 XLST 文件,但问题是当我将 XSLT 转换为 HTML 时,输出与预期不同。问题是,当我运行转换时,我只得到一行 Steps,即只显示第一步,而其他所有步骤都没有。输出可见HERE。可以找到想要的结果HERE
XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<Recipe>
<Title>Beef Parmesan With Garlic Angel Hair Pasta</Title>
<Ingredients>
<Ingredient>
<Name>Beef Cube Steak</Name>
<Quantity>1 1/2 Pounds</Quantity>
<Description>-</Description>
</Ingredient>
<Ingredient>
<Name>Spaghetti Sauce</Name>
<Quantity>One 16 Ounce Jar</Quantity>
<Description>-</Description>
</Ingredient>
<Ingredient>
<Name>Onion</Name>
<Quantity>1</Quantity>
<Description>Sliced Into Thin Rings</Description>
</Ingredient>
<Ingredient>
<Name>Mozzarella Cheese</Name>
<Quantity>1/2 Cup</Quantity>
<Description>Shredded</Description>
</Ingredient>
<Ingredient>
<Name>Green Bell Pepper</Name>
<Quantity>1</Quantity>
<Description>Sliced Into Rings</Description>
</Ingredient>
<Ingredient>
<Name>Green Bell Pepper</Name>
<Quantity>1</Quantity>
<Description>Sliced Into Rings</Description>
</Ingredient>
<Ingredient>
<Name>Angel Hair Pasta</Name>
<Quantity>12 Ounces</Quantity>
<Description>-</Description>
</Ingredient>
<Ingredient>
<Name>Bread Crumbs</Name>
<Quantity>1 Cup</Quantity>
<Description>Italian Seasoned</Description>
</Ingredient>
<Ingredient>
<Name>Garlic</Name>
<Quantity>2 Teaspoons</Quantity>
<Description>Minced</Description>
</Ingredient>
<Ingredient>
<Name>Parmesan Cheese</Name>
<Quantity>1/2 Cup</Quantity>
<Description>Grated</Description>
</Ingredient>
<Ingredient>
<Name>Butter</Name>
<Quantity>1/4 Cup</Quantity>
<Description>-</Description>
</Ingredient>
<Ingredient>
<Name>Olive Oil</Name>
<Quantity>2 Tablespoons</Quantity>
<Description>-</Description>
</Ingredient>
</Ingredients>
<Directions>
<Steps>
<Step>1. Preheat oven to 350 degress Fahrenheit (175 degrees Celsius)</Step>
<Step>2. Cut cube steak into serving size pieces</Step>
<Step>3. Coat meat with the bread crumbs and parmesan cheese</Step>
<Step>4. Heat olive oil in a large frying pan, and saute 1 teaspoon of the garlic for 3 minutes</Step>
<Step>5. Quick fry (brown quickly on both sides) meat</Step>
<Step>6. Place meat in a casserole baking dish, slightly overlapping edges</Step>
<Step>7. Place onion rings and peppers on top of meat, and pour marinara sauce over all</Step>
<Step>8. Bake at 350 degrees FFahrenheit (175 degrees Celsius) for 30 to 45 minutes, depending on the thickness of the meat</Step>
<Step>9. Sprinkle mozzarella over meat and leave in the oven till bubbly</Step>
<Step>10. Boil pasta al dente</Step>
<Step>11. Drain, and toss in butter and 1 teaspoon garlic</Step>
<Step>12. For a stronger garlic taste, season with garlic powder</Step>
<Step>13. Top with grated parmesan and parsley for color. Serve meat and sauce atop a mound of pasta</Step>
</Steps>
<Hint>Make the meat ahead of time, and refrigerate overnight, the acid in the tomato sauce will tenderize the meat even more. If you do this, save the mozzarella till the last minute</Hint>
</Directions>
<Nutritions>
<Nutrient>
<Name>Calories</Name>
<Value>1167</Value>
</Nutrient>
<Nutrient>
<Name>Protein</Name>
<Value>71g</Value>
</Nutrient>
<Nutrient>
<Name>Fat</Name>
<Value>52g</Value>
</Nutrient>
<Nutrient>
<Name>Carbohydrates</Name>
<Value>101g</Value>
</Nutrient>
</Nutritions>
</Recipe>
XSL 文件
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head>
<style>
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black; border: 1px solid black;
</style>
</head>
<body>
<h1>
<xsl:value-of select="Recipe/Title"/>
</h1>
<h4>INGREDIENTS</h4>
<table style="width:100%">
<tr>
<th>Name</th>
<th>Quality</th>
<th>Description</th>
</tr>
<xsl:for-each select="Recipe/Ingredients/Ingredient">
<tr>
<td>
<xsl:value-of select="Name"/>
</td>
<td>
<xsl:value-of select="Quantity"/>
</td>
<td>
<xsl:value-of select="Description"/>
</td>
</tr>
</xsl:for-each>
</table>
<h4>DIRECTIONS</h4>
<table style="width:100%">
<tr>
<th>Step</th>
</tr>
<xsl:for-each select="Recipe/Directions/Steps">
<tr>
<td>
<xsl:value-of select="Step"/>
</td>
</tr>
</xsl:for-each>
</table>
<h4>NUTRIENTS</h4>
<table style="width:100%">
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<xsl:for-each select="Recipe/Nutritions/Nutrient">
<tr>
<td>
<xsl:value-of select="Name"/>
</td>
<td>
<xsl:value-of select="Value"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我们将不胜感激。
【问题讨论】:
标签: xml xslt transformation