【发布时间】:2018-11-08 02:58:18
【问题描述】:
您好,我正在尝试使用 XSLT 样式表方法将我的 XML 文档元素转换为表格格式。
XML 文档
<?xml version="1.0"?>
<?xml-stylesheet href="Assignment2.xsl" type="text/xsl"?>
<cars orderid="199564"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Assignment1.xsd">
<make>Chevy</make>
<model>Colorado</model>
<year>2017</year>
<color>Silver</color>
<engine>
<number_of_cylinders>6</number_of_cylinders>
<fuel_system>fuel injected</fuel_system>
</engine>
<number_of_doors>4</number_of_doors>
<transmission_type>automatic</transmission_type>
<accessories>
<number_of_cylinders>8</number_of_cylinders>
<fuel_system>fuel injected</fuel_system>
</accessories>
</cars>
XLS 样式表(包含表格格式)
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2> Car Information </h2>
<table border="1">
<tr>
<th> Make</th>
<th> Model> </th>
<th> Year </th>
<th> Color </th>
<th> No. of Cylinders </th>
<th> Fuel_System </th>
<th> Number of Doors </th>
<th> Transmission Type </th>
</tr>
<xsl:for-each select="cars">
<tr>
<td><xsl:value-of select="make"/></td>
<td><xsl:value-of select="model"/></td>
<td><xsl:value-of select="year"/></td>
<td><xsl:value-of select="color"/></td>
<td><xsl:value-of select="engine/number_of_cylinders"/></td>
<td><xsl:value-of select="engine/fuel system"/></td>
<td><xsl:value-of select="number_of_doors"/></td>
<td><xsl:value-of select="transmission_type"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我观看了这个 Youtube 视频 https://www.youtube.com/watch?v=BujLy71JY1k,了解如何在 5 分钟内创建 XSLT。我看到那个人将 XLS 样式表文件链接到 XML 文件本身中的 XML。起初我以为我错过了这一部分,所以我回去尝试了它,但它并没有解决问题。我可能错了,但我相信我的 XML 文档和 XLS 文件的格式都是正确的并且做得正确。我在这里遗漏了哪些步骤?
附:我不认为这有什么不同,但我在桌面上的同一目录中同时拥有 XLS 样式表文件和 XML 文档文件。
当我尝试加载 XML 文件时,我不断收到此错误消息XML Error loading stylesheet: X Path parse failure: operator expected message
文件路径的位置 =(C:\Users\Drake\Desktop\Exercise 7.4)
Location of the XML and XLS Stylesheet file
感谢您的反馈德雷克!
【问题讨论】:
-
我推荐使用xsltfiddle.liberty-development.net 来测试你的XSLT,因为这会给你更好的错误信息。请参阅xsltfiddle.liberty-development.net/pPqsHUp 了解您的情况,其中显示错误的实际行号。