【发布时间】:2021-03-26 07:03:56
【问题描述】:
早上好,我是 XLS 的新手,我正在尝试显示一个包含“菜单”项的 XML。但是每道菜都包含许多成分标签,我无法将它们显示在我的表中的列表中。 这是我的 XML:
<Menu>
<dish Id='001'>
<general_info>
<name>Margharita</name>
<description>Mozzarela slices, tomatoes, basil and extra olive oil</description>
<type>Pizza</type>
</general_info>
<nutrition_info>
<ingredient>Mozzarela</ingredient>
<ingredient>tomatoes</ingredient>
<ingredient>basil</ingredient>
<ingredient>olive oil</ingredient>
<ingredient>flour</ingredient>
<dietary_restrictions>Allergic to Gluten</dietary_restrictions>
</nutrition_info>
<price>RS300</price>
</dish>
<dish Id='002'>
<general_info>
<name>Chicken Burger</name>
<description>Chicken regular Hamburger</description>
<type>Burger</type>
</general_info>
<nutrition_info>
<ingredient>bread</ingredient>
<ingredient>chicken</ingredient>
<ingredient>tomato</ingredient>
<ingredient>cheddar</ingredient>
<ingredient>onions</ingredient>
<ingredient>lettuce</ingredient>
<dietary_restrictions></dietary_restrictions>
</nutrition_info>
<price>RS290</price>
</dish>
</Menu>
这是我的 XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2><center>Menu</center></h2>
<table border="1">
<tr bgcolor="orange">
<th>Name</th>
<th>Description</th>
<th>Type</th>
<th>Ingredients</th>
<th>dietary restrictions</th>
<th>Price</th>
</tr>
<xsl:for-each select="Menu/dish">
<tr>
<td><xsl:value-of select="general_info/name"/></td>
<td><xsl:value-of select="general_info/description"/></td>
<td><xsl:value-of select="general_info/type"/></td>
<td>
<ul>
<xsl:for-each select="Menu/dish/nutrition_info">
<li><xsl:value-of select="ingredient"/></li>
</xsl:for-each>
</ul>
</td>
<td><xsl:value-of select="nutrition_info/dietary_restrictions"/></td>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我正在努力实现这样的目标:
Name | Description | TYPE | Ingredients | dietary restrictions | Price
Margharita|.............|Pizza |list of items|......................|......
etc
请注意,每道菜可能有不同数量的成分属性。
【问题讨论】: