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

Subject: Re: <xsl:import> / <xsl:include> Q
From: mxmodi@xxxxxxxxxxxxxxx
Date: Tue, 14 Nov 2000 12:04:11 -0600
Thanks a bunch for your help. This works! However, I am greedy and want to
make this as generic as possible. In the <xsl:include> statement, I want to
pass the href as an <xsl:attribute> and thereby generate the URL
dynamically depending on how the user got there. Here is the sample XSL:

<xsl:stylesheet version="1.0" xmlns:xsl
<xsl:variable name="config" select="document

<xsl:include><xsl:attribute name="href"><xsl:value-of select="$config"

<xsl:template match="/">


<xsl:call-template name="MainJS" />
....more customized JS...


Can I do this? I ran it against saxon and  it gave the following error:

At xsl:include on line 3 : Element must have a "href" attribute

I also tried to use the concat() function within href and that also gave me
an error like the following:
<xsl:include href="concat($config,'Read/MainJS.xsl')" />

 I am not sure what I am trying to do can be done. Any help is appreciated.


Jeni Tennison <mail@xxxxxxxxxxxxxxxx> on 11/14/2000
04:13:24 AM

Please respond to xsl-list@xxxxxxxxxxxxxxxx

Sent by:  owner-xsl-list@xxxxxxxxxxxxxxxx

To:   mxmodi@xxxxxxxxxxxxxxx
cc:   xsl-list@xxxxxxxxxxxxxxxx
Subject:  Re: <xsl:import> / <xsl:include> Q


> I have a design Q on how to implement the <xsl:import>/<xsl:include> in
> 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:

 XSL-List info and archive:

Current Thread