Xml文件不会使用XSLT样式表 [英] Xml file wont use XSLT stylesheet
问题描述
我的XML有问题吗?它不会使用我试图应用的任何样式表。
这就是我的xml的样子。
Is there something wrong with my XML? It wont use any of the stylesheet's I try to apply to it.
This is what my xml looks like.
<?xml version="1.0"?>
<?xml-stylsheet type="text/xsl"
href="Documentation.xsl"?>
<Root>
<Item>
<OrderId>Item Code</OrderId>
<ItemDescription>Item Description</ItemDescription>
<CurrentCount>Current Count</CurrentCount>
<OnOrder>On Order</OnOrder>
</Item>
<Item>
<OrderId>A0001</OrderId>
<ItemDescription>asdjfasdaf</ItemDescription>
<CurrentCount>5</CurrentCount>
<OnOrder>No</OnOrder>
</Item>
然后我的样式表都类似于:
Then my stylesheets are all similar to this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version ="2.0">
<!--this is the first stylesheet output option-->
<xsl:template match="/root">
<html>
<head>
<title>Inventory List</title>
</head>
<body>
<table border="1">
<tr>
<th>OrderId</th>
<th>ItemDescription</th>
<th>CurrentCount</th>
<th>OnOrder</th>
</tr>
<xsl:for-each select="Inventory/Item">
<tr>
<td>
<xsl:value-of select="OrderId"/>
</td>
<td>
<xsl:value-of select="ItemDescription"/>
</td>
<td>
<xsl:value-of select="CurrentCount"/>
</td>
<td>
<xsl:value-of select="OnOrder"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
什么我试过了:
我试过更改href和文件的存储位置。我似乎无法找到它不能工作的原因。
非常感谢任何帮助
What I have tried:
I have tried changing the href and the location the files are stored. I cant seem to find a reason why it wont work.
Any help would be greatly appreciated
推荐答案
XML文件和样式表中都有一些错误。
1。在XML
There are a few errors in both your XML file and the style sheet.
1. In the XML
<?xml-stylsheet type="text/xsl" href="Documentation.xsl"?>
应为
should be
<?xml-stylesheet type="text/xsl" href="Documentation.xsl"?>
stylesheet拼写错误
2。在XSLT中
XML区分大小写,因此语句
stylesheet misspelled
2. In the XSLT
XML is case sensitive, so the statement
<xsl:template match="/root" xmlns:xsl="#unknown"></xsl:template>
应为
should be
<xsl:template match="/Root" xmlns:xsl="#unknown"></xsl:template>
2.1另外考虑添加声明
2.1 Also consider to add the statement
<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes" />
到你的XSLT文件。
见 XSLT< xsl:output>元素 [ ^ ]
2.2 XSLT本质上是递归的
to your XSLT file.
See XSLT <xsl:output> Element[^]
2.2 XSLT is recursive by nature
<table border="1">
<tr>
<th>OrderId</th>
<th>ItemDescription</th>
<th>CurrentCount</th>
<th>OnOrder</th>
</tr>
<xsl:for-each select="Inventory/Item">
<tr>
<td>
<xsl:value-of select="OrderId"/>
</td>
<td>
<xsl:value-of select="ItemDescription"/>
</td>
<td>
<xsl:value-of select="CurrentCount"/>
</td>
<td>
<xsl:value-of select="OnOrder"/>
</td>
</tr>
</xsl:for-each>
</table>
shou ld被更改为
should be changed to
<table border="1">
<tr>
<th>OrderId</th>
<th>ItemDescription</th>
<th>CurrentCount</th>
<th>OnOrder</th>
</tr>
<xsl:apply-templates select="Item" />
</table>
并添加
and add
<xsl:template match="Item">
<tr>
<td>
<xsl:value-of select="OrderId"/>
</td>
<td>
<xsl:value-of select="ItemDescription"/>
</td>
<td>
<xsl:value-of select="CurrentCount"/>
</td>
<td>
<xsl:value-of select="OnOrder"/>
</td>
</tr>
</xsl:template>
最后一件事。你确定XSLT版本吗?
大多数浏览器只支持1.0版
One last thing. Are you sure about the XSLT version?
Most browsers only support version 1.0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">version ="2.0"></xsl:stylesheet>
这篇关于Xml文件不会使用XSLT样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!