[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Javascript as an Include file in xsl

Subject: Re: Javascript as an Include file in xsl
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 10 Oct 2001 19:13:00 +0100
xsl include js
Hi Tom,

> I been brought into an existing project that is XML/XSL based. Even
> with limited XSL experience, I see a huge maintenance nightmare
> evolving. According to the consultants working on the project with
> us, they have found no way to put needed client side JavaScript
> functions into an include file. So all JavaScript functions are
> being duplicated on every page. Since the maintenance of this
> product will fall on my shoulders, I want to find a better solution.
> Is there a way to include a .js file that the XSLT parser will
> accept? Thank you for your time.

It's unclear from your description whether you're talking about
including the Javascript in the *output* of the transformation (which
I assume is HTML) or in the stylesheet itself (i.e. you're using
msxsl:script to get extension functions).

If you're generating HTML, then you can link to an external JavaScript
document by generating a script element in the same way as you would
if you were writing the HTML document directly. In other words, in
your XSLT you should have a literal result element that looks
something like:

  <script language="javascript" type="text/javascript"
          href="script.js" />

The href is likely to be resolved relative to the XML document that's
being transformed (at a guess), not the stylesheet.

If you're using msxsl:script to define extension functions, then
they're right, msxsl:script doesn't have the facility to point to an
external Javascript file. However, you can put the msxsl:script
element in its own stylesheet (e.g. script.xsl) and then include it
into as many other stylesheets as you like using xsl:include:

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

Alternatively, you could use XML entities. Wrap the content of the
Javascript file in a CDATA section (so that you don't have to escape
all the <s and &s within it), and then declare the entity in the
stylesheet that you want to use it in:

<!DOCTYPE xsl:stylesheet [
<!ENTITY script SYSTEM 'script.js'>
]>

and then use &script; to insert the script into the file as desired.

I hope that helps,

Jeni

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


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.