Re: <xsl:import> / <xsl:include> Q

Subject: Re: <xsl:import> / <xsl:include> Q
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 14 Nov 2000 10:13:24 +0000

> I have a design Q on how to implement the <xsl:import>/<xsl:include> in my
> XSL.

I think that you've misunderstood how xsl:import/xsl:include work.
xsl:import and xsl:include are about using templates (and other
constructs) defined in one stylesheet within another stylesheet.  You
seem to be talking about importing Javascript functions embedded in HTML
in one stylesheet into another stylesheet: that's something that XSLT
can't do automatically, because as far as XSLT is concerned Javascript
functions are just a piece of text, nothing more.

The best solution to your problem is probably to have an external
Javascript file and recast the functions so that they take as
arguments the various information that you need to pass into them and
that you are currently coding within the XSLT. For example:

--- MainJS.js ---
function usesFileserver(fileserver) {

and in your XSLT:

  usesFileserver('<xsl:value-of select="$config" />')

If the Javascript is so dependent on XSLT variables that this is
impossible, you should probably have a named or moded template within
MainJS.xsl that includes the text representing certain Javascript
functions whenever it is called. For example:

<xsl:template match="insertMainJS">
  var fileserver = "<xsl:value-of select="$config" />";

Then, import this MainJS.xsl into whichever other stylesheets need
this bit of code, and at the point where the code needs to be
introduced, call the template:

<xsl:include href="MainJS.xsl" />

<xsl:template match="/">
      <script language="Javascript">
        <!-- standard Javascript -->
        <xsl:call-template name="insertMainJS" />
        <!-- customised Javascript -->

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread