har*_*dik 5 xml xslt xsd xml-parsing
我想知道,xml文档中xmlns url是否有真正的含义?
我曾经提到链接。现在,当我将其更改xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
为其他内容时,它停止工作。w3c表示名称空间名称(或URL)仅用于区分xml标签。比为什么更改网址后无法正常工作。
所以我认为,可能与该URL有关,所以尝试了本地设置(没有互联网)..参见以下示例。
XML文档。(first.xml)
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="first.xsl"?>
<!-- Edited by XMLSpy® -->
<catalog>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
<cd>
<title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>
<year>1991</year>
</cd>
<cd>
<title>The dock of the bay</title>
<artist>Otis Redding</artist>
<country>USA</country>
<company>Atlantic</company>
<price>7.90</price>
<year>1987</year>
</cd>
</catalog>
Run Code Online (Sandbox Code Playgroud)
XSLT文档(first.xsl)
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
因此,它的工作环境很好。但是,如果我更改xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
为其他名称,xmlns:xsl="http://www.abc.com"
则会在浏览器中显示错误。
Error loading stylesheet: Parsing an XSLT stylesheet failed.
Run Code Online (Sandbox Code Playgroud)
因此,唯一的问题是,在xmlns中此URL是否有任何实际含义。如果是的话,它比为什么没有互联网并且不能通过更改xsl中的url起作用的原因要多。
它不是一个 URL,它是一个 URI。也就是说,它是一个标识符(名称),而不是位置(地址)。
XML 中的命名空间就像 Java 中的包名;在不同的命名空间中定义了不同的词汇表,以防止冲突并声明词汇表定义的所有权。与包名称一样,命名空间成为该命名空间中元素名称的隐含部分,因此<para>
在 Docbook 命名空间中与<para>
在 DITA 命名空间中没有任何联系。
James Clark 在这里写了一篇关于命名空间的很好的教程:http : //www.jclark.com/xml/xmlns.htm
xmlns 中的这个 URL 有什么真正的含义吗
这是一个基本的 XML 问题,而不是 XSLT 问题。
命名空间 uri 的目的是识别特定的基于 XML 的语言 —— 通过将该实验室的所有元素名称放在同一命名空间中(使它们全部具有相同的命名空间 uri)。
除此之外,命名空间 uri 没有其他用途。
因此,所有 XSLT 元素(和一些属性)都位于"http://www.w3.org/1999/XSL/Transform"
命名空间中,并且任何名称不包含此命名空间-uri 的元素都不是XSLT 元素。
以下是更多示例:
XML 架构:"http://www.w3.org/2001/XMLSchema"
SVG:"http://www.w3.org/2000/svg"
XSL-FO:http://www.w3.org/1999/XSL/Format
XHTML:"http://www.w3.org/1999/xhtml"
XPath 2.0 和 XQuery 函数:http://www.w3.org/2005/xpath-functions
链接:"http://www.w3.org/1999/xlink"
数学ML:"http://www.w3.org/1998/Math/MathML"
因此,通过将样式表中的 XSLT 命名空间-uri 修改为其他内容,您实际上是在说:以关联前缀(在您的情况下为“xsl”)为前缀的名称属于命名空间"http://www.abc.com"
,而不是 XSLT 命名空间 - 因此它们不是 XSLT 元素。
当然,当 XSLT 处理器发现它已被提供了不是 XSLT 元素的元素时,XSLT 处理器会对此进行抱怨。
归档时间: |
|
查看次数: |
5268 次 |
最近记录: |