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



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
="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="config" select="document
('http://sdangel03/com/energytrading/net/tms/TMSconfig.xml')/MESSAGE/CONFIG"

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

<xsl:template match="/">

<html>
<head>

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

</head>
<body>
...
</body>
</html>
</xsl:template>
</xsl:stylesheet>

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.

Maulik








Jeni Tennison <mail@jenitennison.com>@mulberrytech.com on 11/14/2000
04:13:24 AM

Please respond to xsl-list@mulberrytech.com

Sent by:  owner-xsl-list@mulberrytech.com


To:   mxmodi@duke-energy.com
cc:   xsl-list@mulberrytech.com
Subject:  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






 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]