【发布时间】:2019-03-27 05:41:18
【问题描述】:
- 我有一个带有命名空间 ns2 和默认命名空间的 XML 文档:
<ns2:Products xmlns="https://www.schema.product.com" xmlns:ns2="https://www.schema.products.com">
<Product ProductId="1">
<ProductName> Hộp Hoa Hồng Trắng</ProductName>
<ProductPrice>550000</ProductPrice>
<ProductImage>https://dienhoa24gio.net//assets/upload/product/20-09-2015/hop-hoa-hong-trang-1442711392/274_default.jpg</ProductImage>
</Product>
<Product ProductId="2">
<ProductName>An Lành</ProductName>
<ProductPrice>780000</ProductPrice>
<ProductImage>https://dienhoa24gio.net//assets/upload/product/17-10-2015/an-lanh-1445039808/274_default.jpg</ProductImage>
</Product>
</ns2:Products>
和xsl文件显示表格,使用xml文件的数据
<xsl:template match="//*[local-name()='Products']">
<table border="1">
<tr>
<th>name</th>
<th>price</th>
<th>image</th>
</tr>
<xsl:for-each select="//*[local-name()='Product']">
<tr>
<td><xsl:value-of select="//*[local-name()='ProductName']"/></td>
<td><xsl:value-of select="//*[local-name()='ProductPrice']"/></td>
<td><xsl:value-of select="//*[local-name()='ProductImage']"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
- 我导入 2 个文件(xml 和 xsl)并运行 jsp
<c:import url="test.xml" var="xmlDoc" charEncoding="UTF-8"/>
<c:import url="test.xsl" var="xslDoc" charEncoding="UTF-8"/>
<x:transform xml="${xmlDoc}" xslt="${xslDoc}"/>
但是当运行jsp页面时,行表的数据是一样的我不知道
<table border="1">
<tr>
<th>name</th><th>price</th><th>image</th>
</tr>
<tr>
<td> Hộp Hoa Hồng Trắng</td><td>550000</td><td>https://dienhoa24gio.net//assets/upload/product/20-09-2015/hop-hoa-hong-trang-1442711392/274_default.jpg</td>
</tr>
<tr>
<td> Hộp Hoa Hồng Trắng</td><td>550000</td><td>https://dienhoa24gio.net//assets/upload/product/20-09-2015/hop-hoa-hong-trang-1442711392/274_default.jpg</td>
</tr>
<tr>
<td> Hộp Hoa Hồng Trắng</td><td>550000</td><td>https://dienhoa24gio.net//assets/upload/product/20-09-2015/hop-hoa-hong-trang-1442711392/274_default.jpg</td>
</tr>
<tr>
<td> Hộp Hoa Hồng Trắng</td><td>550000</td><td>https://dienhoa24gio.net//assets/upload/product/20-09-2015/hop-hoa-hong-trang-1442711392/274_default.jpg</td>
</tr>
<tr>
<td> Hộp Hoa Hồng Trắng</td><td>550000</td><td>https://dienhoa24gio.net//assets/upload/product/20-09-2015/hop-hoa-hong-trang-1442711392/274_default.jpg</td>
</tr>
</table>
请帮我修复这个错误, 非常感谢
【问题讨论】:
-
命名空间似乎不是实际问题的一部分。可能你想编辑你的标题。
标签: xml xslt namespaces xml-namespaces