谁能告诉我为什么下面给我的错误:Keyword xsl:template may not contain xsl:next-match
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "3.0">
<xsl:template match="*">
<xsl:value-of select="name(.)"/><br/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="rc2">
<h1>this is first match</h1>
<xsl:next-match/>
</xsl:template>
</xsl:stylesheet>
虽然这个版本没有错误,但当然它只匹配一个
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "3.0">
<xsl:template match="*">
<xsl:value-of select="name(.)"/><br/>
<xsl:apply-templates/>
<xsl:next-match/>
</xsl:template>
<xsl:template match="rc2">
<h1>this is first match</h1>
</xsl:template>
</xsl:stylesheet>
我的测试XML文件是:
<?xml version="1.0"?>
<rc2/>
(题型修改编辑)我正在使用Msxml2.XSLTemplate.6.0, msxml2 . freethreedddomdocument .6.0和Msxml2.DOMDocument.6.0
您使用什么XSLT处理器?next-match需要XSLT 2.0,我猜您使用的是XSLT 1.0处理器。
您在xsl:stylesheet标题中说了version="3.0",这使事情变得复杂。如果样式表显示version="3.0",并且您使用XSLT 1.0处理器运行它,那么它将以"向前兼容模式"运行。在这种模式下,XSLT 1.0中不可用的XSLT指令只有在实际执行时才会导致错误。其思想是允许您运行样式表,通过询问处理器支持什么,例如使用system-property()或element-available()函数,可以动态地决定执行哪些代码模板。