xsl-list
[Top] [All Lists]

[xsl] should apply-imports apply template rule in the same stylesheet?

2011-07-06 08:06:59

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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>