这是我的练习代码应用于基本的xml文档:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns="http://www.xml.com/books"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>XSLT</title>
<style>
h1, p {margin:0;}
</style>
</head>
<body>
<xsl:for-each select="/bookstore/book">
<h1><xsl:value-of select="title"/></h1>
<p>
by
<xsl:for-each select="author">
<xsl:value-of select="text()"/>
</xsl:for-each>
<xsl:text>, </xsl:text>
<xsl:value-of select="year"/><br/>
Price: £<xsl:value-of select="price"/><br/>
<xsl:if test="photo">
<img style="height:200px;">
<xsl:attribute name="src">
<xsl:value-of select="photo"/>
</xsl:attribute>
</img>
</xsl:if>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
命名空间只是没有点击我。我理解为什么他们在那里,他们是目的,但我不明白为什么这样的事情就像他们一样。
任何帮助都非常感谢谢谢!
答案 0 :(得分:0)
您需要围绕合格名称(或简称QNames)的概念。 XML中的许多实体(如元素和属性)由QNames标识,QNames由命名空间和本地名称组成。例如,这个元素:
<foo:bar xmlns:foo="qwertyuiop">
由QName
标识{quertiuiop}bar
请注意,foo
不是是QName的一部分。像foo
这样的命名空间前缀是简写,可以避免我们反复输入命名空间字符串。另请注意,命名空间字符串qwertyuiop
是任意的。通常,按照惯例,URI被用作命名空间标识符,但这只是因为希望这可以防止冲突。如果我拥有jimrussell.us
域,我对使用名为http://jimrussell.us/xsl/functions
的命名空间非常有信心。
考虑一下:对于XML处理器(如果它正常工作),这三个XML文档完全等效:
<foo:root xmlns:foo="urn:foo:space">
<foo:child/>
</foo:root>
<xxx:root xmlns:xxx="urn:foo:space">
<yyy:child xmlns:yyy="urn:foo:space"/>
</xxx:root>
<root xmlns="urn:foo:space">
<child/>
</root>
在上一个例子中,我终于开始使用默认命名空间,其中没有前缀的所有内容都存在于该命名空间中。