This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: [Fwd: xsl:import (was Re: Multiple views on an xml document)]
- To: Jeni Tennison <mail at jenitennison dot com>
- Subject: Re: [Fwd: xsl:import (was Re: Multiple views on an xml document)]
- From: Lewis <lewis at ndsapps dot com>
- Date: Tue, 07 Nov 2000 08:51:54 -0500
- CC: xsl-list at mulberrytech dot com
- Organization: NDS
- References: <3A070E30.5F9B1EBD@ndsapps.com> <235149474.20001107094747@jenitennison.com>
- Reply-To: xsl-list at mulberrytech dot com
Thank you. I think I like the first approach (Entity) better as it's just
a stright insert of html code; I don't need to manipulate it.
Thanks again,
Lewis
Jeni Tennison wrote:
> Lewis,
>
> > Along these same lines, I have some html code I want to include in
> > all of my html documents. A small example:
> [amended example]
> > <?xml version="1.0"?>
> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">>
> >
> > <style type="text/css" id="NOF_STYLE_SHEET">
> > DIV#Picture25LYR { position:absolute; visibility:inherit; }
> > DIV#Picture26LYR { position:absolute; visibility:inherit; }
> > DIV#Picture27LYR { position:absolute; visibility:inherit; }
> > </style>
> >
> > </xsl:stylesheet>
> >
> > In the xsl file that creates my html, I include the line:
> >
> > <xsl:import href="test.xsl"/>
>
> xsl:import and xsl:include are designed to allow you to use the
> variables, keys, templates and other XSLT constructs from a stylesheet
> in another stylesheet, *not* to include a particular snippet of XML in
> your stylesheet.
>
> There are two ways of keeping XML snippets in separate files and
> including them in your stylesheet. In both, the snippet is stored in a
> separate file. So, you create an XML file that contains the text that
> you want to include. For example, style.xml might be:
>
> --- style.xml ---
> <style type="text/css" id="NOF_STYLE_SHEET">
> DIV#Picture25LYR { position:absolute; visibility:inherit; }
> DIV#Picture26LYR { position:absolute; visibility:inherit; }
> DIV#Picture27LYR { position:absolute; visibility:inherit; }
> </style>
> ---
>
> The first is to use entities. Within your stylesheet, declare the
> entity within a DOCTYPE at the top of the page:
>
> <!DOCTYPE xsl:stylesheet [
> <!ENTITY style SYSTEM 'style.xml'>
> ]>
>
> Then, at the point where you want to include the contents of that
> file, refer to the entity you've defined with an entity reference:
>
> <xsl:template match="/">
> <html>
> <head>
> <title>My Page</title>
> <!-- CSS styles included here -->
> &style;
> </head>
> <body>
> ...
> </body>
> </html>
> </xsl:template>
>
> The contents of your style.xml file will then be included wherever you
> reference the entity.
>
> The second option is to use the document() function in XSLT to pull in
> the contents of the style.xml file. The call:
>
> document('style.xml')
>
> accesses the XML document node, and you can then copy it to insert it
> into your output:
>
> <xsl:template match="/">
> <html>
> <head>
> <title>My Page</title>
> <!-- CSS styles included here -->
> <xsl:copy-of select="document('style.xml')/style" />
> </head>
> <body>
> ...
> </body>
> </html>
> </xsl:template>
>
> The two approaches each have advantages and disadvantages. The
> entities approach is very useful for inserting any well-formed XML
> into your stylesheet: it could be used to insert five elements, or a
> piece of text, for example. With document(), on the other hand, the
> XML being imported has to be XML, and has to be a *document* - that
> means it has to have one, and only one, element. On the other hand,
> the document() approach allows you more easily to *process* the
> nodes that you pull in, which means that the included document can
> itself be transformed before being outputted.
>
> I hope that this helps,
>
> Jeni
>
> ---
> Jeni Tennison
> http://www.jenitennison.com/
--
Lewis Cunningham
NDS Systems
Tel : 727-538-2250
Mail: lewis@ndsapps.com
Web : www.ndsapps.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list