Xml 我的XSLT中有什么错误?
这是我的xml文件Xml 我的XSLT中有什么错误?,xml,xslt,xpath,Xml,Xslt,Xpath,这是我的xml文件 <html xmlns="http://www.w3schools.com"> <body> <shelf> <cd id="el01"> <artist>Elton John</artist> <title>Circle of Life</title>
<html xmlns="http://www.w3schools.com">
<body>
<shelf>
<cd id="el01">
<artist>Elton John</artist>
<title>Circle of Life</title>
<country>UK</country>
<company>Spectrum</company>
<price>10.90</price>
<year>1999</year>
<description>As heard in the Lion King.</description>
</cd>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.
</description>
</book>
</shelf>
</body>
</html>
埃尔顿·约翰
生命周期
英国
谱
10.90
1999
正如在《狮子王》中听到的那样。
马修·甘巴德拉
XML开发人员指南
计算机
44.95
2000-10-01
深入了解如何创建应用程序
使用XML。
这是我的XSL文件
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<!-- TODO customize transformation rules
syntax recommendation http://www.w3.org/TR/xslt
-->
<xsl:template match="/">
<html>
<head>
<title>The Shelf</title>
</head>
<body>
<h1>The Shelf</h1>
<xsl:apply-templates select="shelf"/>
</body>
</html>
</xsl:template>
<xsl:template match="//shelf">
<xsl:for-each select="cd|book">
<xsl:value-of select="title"/>
</xsl:for-each>
</xsl:template>
架子
架子
我的输出只是浏览器中的“书架”。我哪里错了?你的select=“shelf”错了。如果你把它取下来就行了。或者尝试select=“html/body/shelf”。您的select=“shelf”错误。如果你把它取下来就行了。或者尝试select=“html/body/shelf”。您的行
将应用于根节点(即html/shelf)的上下文中。此级别没有工具架节点
将该行更改为
就足够了。您的行
将应用于根节点(即html/shelf)的上下文中。此级别没有工具架节点
将该行更改为
就足够了。您有两个问题
<xsl:stylesheet xmlns:data="http://www.w3schools.com" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<!-- TODO customize transformation rules
syntax recommendation http://www.w3.org/TR/xslt
-->
<xsl:template match="/">
<html>
<head>
<title>The Shelf</title>
</head>
<body>
<h1>The Shelf</h1>
<xsl:apply-templates select="//data:shelf"/>
</body>
</html>
</xsl:template>
<xsl:template match="//data:shelf">
<xsl:for-each select="data:cd|data:book">
<p><xsl:value-of select="data:title"/></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
架子
架子
您有两个问题
<xsl:stylesheet xmlns:data="http://www.w3schools.com" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<!-- TODO customize transformation rules
syntax recommendation http://www.w3.org/TR/xslt
-->
<xsl:template match="/">
<html>
<head>
<title>The Shelf</title>
</head>
<body>
<h1>The Shelf</h1>
<xsl:apply-templates select="//data:shelf"/>
</body>
</html>
</xsl:template>
<xsl:template match="//data:shelf">
<xsl:for-each select="data:cd|data:book">
<p><xsl:value-of select="data:title"/></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
架子
架子
+1用于发现名称空间问题!。但是请注意,通常使用/
快捷方式并不好,因为它会在所有级别查找所有匹配的节点,这在大型文档中可能效率低下。如果您知道实际路径,最好选择它。+1用于发现名称空间问题!。但是请注意,通常使用/
快捷方式并不好,因为它会在所有级别查找所有匹配的节点,这在大型文档中可能效率低下。如果你知道的话,最好选择实际的路径。