This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: what is the difference between XSL:import and XSL:include


Hi Doug

>What is the difference between XSL:import and XSL:includ and how do they
>work?
>
For a detailed answer see either the specs or a book such as Mike
Kay's XSLT programmers reference.  Here is the shortest useful summary
I can think of, with the idea that you may not need to know the
details.

In your example, import and include would have the same effect.
In both cases the processor will build a complete transform from the
components you provide, but how this is done is different.

xsl:include is intended to be like include in other languages - e.g. C
#include.  It is textual inclusion (other than for some fiddling with
the stylesheet element itself).  Use it to make up a transform out of
several independent bits - as in your example.

xsl:import is related to inheritance in object oriented languages.  It
is used where you want to make a transform which is like another
except for a few templates or global variables.  You are allowed to
redefine things in a way which would be illegal if xsl:include were
used.  Where there is ambiguity (in selecting a definition or matching
a node with a template) the one 'nearest' the top level stylesheet is
used.  The exact rules as to what 'nearest' means are quite
complicated and not always implemented correctly, so if you use
xsl:import keep it simple.

Use xsl:include where the other stylesheet is 'part of' the one you
are writing.

Use xsl:import where the stylesheet you are writing is 'like' or
'based on' the one you are importing.

>Let's say I have the following stylesheet (one.xsl):
><?xml version="1.0"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>  <xsl:import href="anothersheet.xsl" />
>  <xsl:import href="yetanotherone.xsl" />  
>  <xsl:template match="/">
>   <p align="left">
>    <xsl:apply-templates/>
>   </p>
>  </xsl:template>
></xsl:stylesheet>
>
>Say "anothersheet.xsl" looks like this:
><?xml version="1.0"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>  <xsl:template match="title">
>   <h1>
>    <xsl:apply-templates/>
>   </h1>
>  </xsl:template>
></xsl:stylesheet>
>
>And "yetanotherone.xsl" is thus:
><?xml version="1.0"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>  <xsl:template match="text">
>   <h1>
>    <xsl:apply-templates/>
>   </h1>
>  </xsl:template>
></xsl:stylesheet>
>
>What would the resulting page look like to the XSL processor if you use
><include> vs <import>? For example, would the processor see one large page,
>or just links to three?
>
Regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@melvaig.co.uk

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]