Subject: Re: [xsl] should apply-imports apply template rule in the same stylesheet? From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx> Date: Wed, 6 Jul 2011 09:50:19 -0400 |
The last paragraph of section 5.8 (Built-in Template Rules) of the XSLT 1.0 spec reads: "The built-in template rules are treated as if they were imported implicitly before the stylesheet and so have lower import precedence than all other template rules. Thus, the author can override a built-in template rule by including an explicit template rule." Therefore, <xsl:apply-imports/> is invoking the built-in rule for the root node, which is just <xsl:apply-templates/>. Seems right to me. :) -Brandon :) On Wed, Jul 6, 2011 at 9:06 AM, Martin Honnen <Martin.Honnen@xxxxxx> wrote: > > Recently I came across a stylesheet that did not include nor import any > other modules but used apply-imports, as in the following reduced sample: > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > > <xsl:template match="/"> > <html> > <head> > <title>Test</title> > </head> > <body> > <xsl:apply-imports/> > </body> > </html> > </xsl:template> > > <xsl:template match="foo"> > <p> > <xsl:value-of select="."/> > </p> > </xsl:template> > > </xsl:stylesheet> > > My initial understanding and expectation was that initially the template > matching the document node (match="/") would be applied and output the html > element with its head and body child element but that the apply-imports > would only look for imported template rules and that way would not apply the > template with match="foo" in the same stylesheet. > > Yet when I run the stylesheet with Saxon 6.5.5 or 9.3.0.5 against the most > simple XML input > > <foo>foo 1</foo> > > the result is containing a <p>foo 1</p> element, as in > > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> > > <title>Test</title> > </head> > <body> > <p>foo 1</p> > </body> > </html> > > xsltproc on the other hand outputs > > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> > <title>Test</title> > </head> > <body></body> > </html> > > so there the template match="foo" is not applied by the apply-imports. > > The XSLT 1.0 spec in its usual brevity says: > "xsl:apply-imports processes the current node using only template rules > that were imported into the stylesheet element containing the current > template rule". > > Based on that it seems the apply-imports should not result in applying the > template with match="foo" in the same stylesheet. > > On the other hand most other processors I have tried (Mozilla's, Opera's, > IE's) seem to agree with Saxon and not with xsltproc so my simple assumption > that a template in the same stylesheet is not an imported one seems wrong. > > What are your thoughts? > > > -- > > Martin Honnen --- MVP Data Platform Development > http://msmvps.com/blogs/martin_honnen/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] should apply-imports apply te, Martin Honnen | Thread | Re: [xsl] should apply-imports appl, Martin Honnen |
[xsl] should apply-imports apply te, Martin Honnen | Date | Re: [xsl] should apply-imports appl, Martin Honnen |
Month |