I have uncovered a significant difference in the way xsltproc and Saxon
(both 6 and 9)
handle xsl:apply-imports when using a template mode. It seem that Saxon
is doing the wrong thing here, but I wanted to ask if others interpret it
this way. I cannot find anything in the archive on this subject.
I'm processing this simple document book.xml:
----------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<book>
<title>My book title</title>
<para>My first para</para>
</book>
----------------------------------------------------------------------------------------------------------------------------
with this stylesheet (modetest.xsl):
----------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:import href="no-mode.xsl"/>
<xsl:param name="myflag" select="1"/>
<xsl:template match="book">
<xsl:apply-templates select="." mode="inside_mode"/>
</xsl:template>
<xsl:template match="book" mode="inside_mode">
<xsl:choose>
<xsl:when test="$myflag != 0">
<xsl:message>Reached apply-imports in modetest.xsl</xsl:message>
<xsl:apply-imports/>
</xsl:when>
<xsl:otherwise>
<xsl:message>Reached otherwise in modetest.xsl</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="inside_mode">
<xsl:message>reached fallback in modetest.xsl for element
<xsl:value-of select="local-name()"/></xsl:message>
</xsl:template>
</xsl:stylesheet>
----------------------------------------------------------------------------------------------------------------------------
And the imported no-mode.xsl stylesheet is:
----------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="book">
<xsl:choose>
<xsl:when test="$myflag != 0">
<xsl:message>Reached when in no_mode.xsl</xsl:message>
<xsl:apply-imports/>
</xsl:when>
<xsl:otherwise>
<xsl:message>Reached otherwise in no_mode.xsl</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
----------------------------------------------------------------------------------------------------------------------------
When I apply modetest.xsl to book.xml using xsltproc, the message output is
just:
Reached apply-imports in modetest.xsl
When I apply modetest.xsl to book.xml using Saxon, the output is:
Reached apply-imports in modetest.xsl
reached fallback in modetest.xsl for element title
reached fallback in modetest.xsl for element para
According to Saxon author Michael Kay's website, his description of
xsl:apply-imports is:
"The effect is to search for a template that matches the current node and
that is defined in a stylesheet that was imported (directly or indirectly,
possibly via xsl:include) from the stylesheet containing the current
template, and whose mode matches the current mode. If there is such a
template, it is activated using the current node. If not, the call on
xsl:apply-imports has no effect."
There is no template matching on book in mode="inside_mode" in the imported
stylesheet, so the call on xsl:apply-imports should have no effect. That is
what I see when I process with xsltproc. However, Saxon continues
processing the children of book in that mode, even though there is no
xsl:apply-templates to trigger such processing. Why is Saxon applying
templates in mode="inside_mode" to the children of book?
Bob Stayton
Sagehill Enterprises
bobs(_at_)sagehill(_dot_)net
--~------------------------------------------------------------------
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>
--~--