[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: Re: what is the difference between XSL:import and XSL:include
From: tcn@xxxxxxxxxxxxx (Trevor Nash)
Date: Sat, 04 Aug 2001 09:53:26 GMT
xslt import include difference
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@xxxxxxxxxxxxx

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.