This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


Maulik,

> 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" />";
  ...
</xsl:template>

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="/">
  <html>
    <head>
      <script language="Javascript">
        <!-- standard Javascript -->
        <xsl:call-template name="insertMainJS" />
        
        <!-- customised Javascript -->
        ...
      </script>
    </head>
    <body>
      ...
    </body>
  </html>
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]