Re: [xsl] XSL import

Subject: Re: [xsl] XSL import
From: Abel Online <>
Date: Mon, 28 Aug 2006 17:51:23 +0200
Hi Bernie,

It is not possible to include on any other place than as a top-level element (this counts for both xsl:inclue and xsl:import). Perhaps you can split your XSL and do something like the following and put them in main.xsl:

<xsl:import href="header.xsl" />
<xsl:import href="body.xsl" />
<xsl:import href="footer.xsl" />

Another approach you could use, is using the xsl:apply-templates and call a matching rule from the included xsl file. Something like this (should go in the header.xsl):

<xsl:template match="field/text" mode="header">
  .. do you header thing ...

Place the following on the place where you wanted the included XSL:
<xsl:apply-templates select="text/[@name='activeTab']" mode="header" />

Now you can place the xsl:import command anywhere you like (as a top-level element, that is) and you can call the xsl:apply-templates whenever you wanted to "include" the header. The reason I add "mode" attribute is because I think you would otherwise have a conflicting match.



Abel Braaksma

Bernie wrote:

Excuse my english, I'll try to explain that as better as I can:

I have a group of XSL that use common HTML and XSL elements. I'd like
to make a new and unique XSL as an include which gathers these common

Concise example:


<?xml version="1.0" encoding="UTF-8"?>
    <text name="activeTab">tab one</text>
    <text name="title">The title of the page</text>

Main XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="";>
<xsl:output method="html" encoding="utf-8" indent="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />

 <xsl:template match="/">
   <html xmlns="";>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Bla bla bla</title>
   <link href="/css/main.css" rel="stylesheet" type="text/css" />
     <xsl:apply-templates />

 <xsl:template match="theForm">
      <xsl:apply-templates />

 <xsl:template match="fields">
    <div id="divGenContainer">


       <div id="divContents">
            <xsl:value-of select="text[@name='title']" />



The include file (XSL/HTML) should have some like the following content:

<xsl:value-of select="text[@name='activeTab']" />


Thanx in advance.

On 8/28/06, Florent Georges <darkman_spam@xxxxxxxx> wrote:

Bernie WROTE:

> How can I insert an XSL into an specific location in another
> (xsl:import) and use sibling tags in both xsl?

  It is maybe my low level of knowledge in English, but I didn't
understand your question.  Could you reformulate?  An simple example
could be more precise than prose.



 uncompressed/chunked Mon Aug 28 14:13:42 GMT 2006


Dicouvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet !
Yahoo! Questions/Riponses pour partager vos connaissances, vos opinions et vos expiriences.

Current Thread