关键字的xsl:模板可能不包含XSL:下一个匹配

问题描述:

有人能解释我为什么要在下面给我的错误:在这个版本中没有给出错误 Keyword xsl:template may not contain xsl:next-match关键字的xsl:模板可能不包含XSL:下一个匹配

<?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.FreeThreadedDOMDocument.6.0和Msxml2.DOMDocument.6.0

您使用的是哪种XSLT处理器? xsl:next-match需要XSLT 2.0,我的猜测是您使用的是XSLT 1.0处理器。

您在xsl:样式表头中说过version =“3.0”,这会使事情变得复杂。如果样式表的版本=“3.0”,并且您使用XSLT 1.0处理器运行它,则它将以“forwards-compatibility mode”运行。在这种模式下,XSLT 1.0中不可用的XSLT指令只有在实际执行时才会导致错误。这个想法是允许你运行样式表,通过询问处理器它支持什么,例如使用system-property()或element-available()函数来动态决定要执行的代码模板。

+0

Msxml2.XSLTemplate.6.0,Msxml2.FreeThreadedDOMDocument.6.0,Msxml2.DOMDocument.6.0,我仍在阅读关于xslt 2.0和3.0的支持,但您的回答让我感觉很满意,因为我已经尝试了很多它的变化似乎只在实际执行“下一次匹配”时才会出现错误 –