xsl-list
[Top] [All Lists]

Re: [xsl] stylesheet organisation

2011-09-03 04:42:46
Jesper,

I think you made some thinking errors in your contribution

I disagree strongly that "you never really need to use xsl:import. "
In complex XSLTs I use both xsl:import and xsl:include simply to make sure
I don't end up with ambiguous rules (I hate warnings coming from the execution of my stylesheets),
still allowing me to make customizations,
and I don't have to spend hours checking that the order is right.
Would not know how to manage that without using both elements together

I always thought that if there is an ambiguity between templates,
the processor can just take one at random, not necessarily the last one.
I might be wrong, would not make much of a difference, since I don't want the warnings anyway;
Maybe I can encourage someone who knows for certain from the spec to step in

Let's have a B.xsl with a template match = "*" copying <B/> to the output tree
and have a C.xsl with a template match = "*" copying <C/> to the output tree

all we have is
    <xsl:template match="*">
        <B/>
    </xsl:template>
in B.xsl
and something similar in C.xsl

Case 1
----------
    <xsl:include href="B.xsl"/>
    <xsl:include href="C.xsl"/>
You should get a warning: ambiguous rule... processor can pick any rule it wants, I thought, Saxon 9.3PE picks <C/>, does not contradict with what you are saying, but I still gets you a warning

Case 2
-----------
   <xsl:import href="B.xsl"/>
    <xsl:include href="C.xsl"/>
will get us <C/>, you tell me it is because of the order, I say it is because of the fact that the <xsl:import> pushes down the priority of the B.xsl template

Case 3
----------
    <xsl:import href="B.xsl"/>
    <xsl:import href="C.xsl"/>
I did not mention this case, I try to avoid in my stylesheets that this rule comes into play
end result is <C/> since B has lower precedence as it comes first
In my opinion this is the only case of the 3 really triggered by the order

Please be careful in your contributions.
If somewhere in your contribution you have some sentence like "it is not true that",
so in fact claiming that my statements were wrong,
can I please suggest that you then read
http://www.w3.org/TR/2007/REC-xslt20-20070123/#element-include
and the next section on xsl:import
before contributing
(or read Michael Kay's book on page 357 and 372 , simply the first paragraph on the xsl element will do)
you can also follow a link to MKs definition from this website
http://www.xmlplease.com/xmltraining/xslt-by-example/xslt-by-example.html :-)

cheers

Geert





At 10:17 3/09/2011, you wrote:
Mark asked:

"Is there a significant difference between xsl:import and xsl:include
worth learning?"

The only difference between xsl:import and xsl:include is that
xsl:import must be the very first child of xsl:stylesheet.

This means that if the importing stylesheet has templates that matches
with same priority as the templates in the imported stylesheet, the
templates in the importing stylesheet are sure to win out because they
are after the templates in the imported stylesheet.

That is you never really need to use xsl:import. If you make sure that
an xsl:include is the very first child of xsl:stylesheet, it works
exactly as if xsl:import had been used.

It is not true that "in general the rules and definitions in an
including stylesheet have the same precedence as the ones in the
included stylesheet."

Using xsl:include simply means that you don't know about precedence
without having to take a look in the merged stylesheets in order to
find out what comes last. That is not necessary when you use
xsl:import because the imported templates must come first.

Cheers
Jesper Tverskov
http://www.xmlplease.com

--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>