2

Could someone explain me why the following gives me the error: 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>

while this version gives no error, but of course it does only one 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:next-match/>
</xsl:template>

<xsl:template match="rc2">
  <h1>this is first match</h1>
</xsl:template>

</xsl:stylesheet>

my test xml file is:

<?xml version="1.0"?>
<rc2/>

(question revision edit) i'm using Msxml2.XSLTemplate.6.0, Msxml2.FreeThreadedDOMDocument.6.0 and Msxml2.DOMDocument.6.0

neu-rah
  • 1,662
  • 19
  • 32

1 Answers1

4

What XSLT processor are you using? xsl:next-match requires XSLT 2.0, and my guess is that you are using an XSLT 1.0 processor.

You have said version="3.0" in the xsl:stylesheet header, which complicates things. If the stylesheet says version="3.0" and you run it using an XSLT 1.0 processor, then it will run in "forwards-compatibility mode". In this mode, XSLT instructions that aren't available in XSLT 1.0 cause an error only if they are actually executed. The idea is to allow you to run stylesheets in which you decide dynamically which code templates to execute, by asking the processor what it supports, for example using the system-property() or element-available() functions.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Msxml2.XSLTemplate.6.0, Msxml2.FreeThreadedDOMDocument.6.0, Msxml2.DOMDocument.6.0, i'm still reading about the xslt 2.0 and 3.0 support, but your answer makes fulll sense to me because i've tryed a lot of variations at it seems that the error only occours when the "next-match" is actually executed – neu-rah Mar 28 '14 at 17:56