【问题标题】:Create a XSLT sheet from a XSL document? Not working? Done both the XLT doc and XLS Stylesheet从 XSL 文档创建 XSLT 工作表?不工作?完成了 XLT 文档和 XLS 样式表
【发布时间】: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

感谢您的反馈德雷克!

【问题讨论】:

标签: html xml xslt


【解决方案1】:

替换

<td><xsl:value-of select="engine/fuel system"/></td>

<td><xsl:value-of select="engine/fuel_system"/></td>

【讨论】:

  • 太棒了!!:) 非常感谢!我的朋友,你的眼光绝对不错!
猜你喜欢
  • 1970-01-01
  • 2016-01-03
  • 2012-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多