2012-06-19 44 views
0

我不明白为什么xsl:param给了我一个错误'Keyword xsl:param可能不会用在命名空间http://www.w3.org/TR/WD-xsl中。在下面的样式表声明的xsl代码中。xsl:param命名空间错误(可能不会在名称空间中使用)

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="uri:xsl"> 

由于XML

<?xml version="1.0" encoding="ISO-8859-1"?> 
<catalog> 
    <cd n="a"> 
     <title>Empire Burlesque</title> 
     <artist>Bob Dylan</artist> 
     <country>USA</country> 
     <company>Columbia</company> 
     <price>10.90</price> 
     <year>1985</year> 
    </cd> 
</catalog> 

和XSL代码

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="uri:xsl"> 

<xsl:param name="test" select="'a'"/> 

<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"> 

<xsl:choose> 
    <xsl:when match=".[@n = $test]"> 
     <tr> 
     <td><xsl:value-of select="title" /></td> 
     <td><xsl:value-of select="artist" /></td> 
     </tr> 
    </xsl:when> 
    <xsl:otherwise> 

    </xsl:otherwise> 
</xsl:choose> 

     </xsl:for-each> 
    </table> 
    </body> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 

我不能改变样式表声明。仔细查看w3c文档,我可以将param声明为样式表的子代,并且不需要在模板中。

+0

查看w3c文档,您首先不会使用XSL(附加到'xsl'前缀的名称空间很重要)。 – Lucero

回答

2

如果你的东西不在命名空间http://www.w3.org/1999/XSL/Transform那么它不是一个XSLT样式表,我不知道它是什么。没有XSLT处理器可以做任何有用的事情。有可能是某种语言的命名空间“uri.xsl”,但如果有的话,我从来没有遇到它,我不知道它可能是什么。

1

我看到你的XSLT三个错误:

1)您有在变换的开始两个处理指令。你应该只使用一个,如果有的话。

2)stylesheet元素命名空间应http://www.w3.org./1999/XSL/Transform

3)你缺少样式表版本属性

除了这几点,你的样式应该工作。

+0

我更新了上面的代码。你对(1)是正确的,但是我需要声明,因为当匹配=“[@ n = $ test]”>时需要使用。反对 Steven

+0

@Steven,你对'uri:xsl'的评论没有任何意义 - 你需要提供更多信息。 – Lucero

+0

我正在使用具有该声明的遗留代码。当我使用http://www.w3.org替换uri:xsl时./1999/XSL/Transform元素不再是函数,因为它会是期待测试而不是比赛。 – Steven

相关问题