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

Re: Function call to set a variable

Subject: Re: Function call to set a variable
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 09 Oct 2000 14:45:10 +0100
javascript function set variable
Tomas,

>I am trying to set a variable to the value that is returned
>by one of my javascript functions:
>
><xsl:variable name="Language">getLanguage()</xsl:variable>
>
>The example above does not work, but is it possible to call
>my getLanguage() function and set the variable to this value?
>An in that case, how?

There isn't a standard way of incorporating scripted functions into XSLT
1.0.  However, MSXML has an extension element, msxsl:script, that allows
you to do so.  To use it, you have to be using MSXML as your XSLT Processor
(e.g. be doing client-side processing with IE).  Within your stylesheet (on
the xsl:stylesheet element), you have to specify two namespaces: the msxsl
namespace that the extension element belongs to:

  xmlns:msxsl="urn:schemas-microsoft-com:xslt"

and a namespace for your functions, which can be anything you like, but
should be something that you have control over, e.g.:

  xmlns:user="tomas.olsson@xxxxxxxxxxxxx"

This gives a start tag for the xsl:stylesheet element that looks like:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:user="tomas.olsson@xxxxxxxxxxxxx"
                version="1.0">

You then need to define your functions within an msxsl:script element at
the top level of the stylesheet.  The msxsl:script element takes two
attributes: 'language', which gives the language the functions are written
in (i.e. Javascript), and 'implements-prefix', which gives the prefix for
the namespace you're using (i.e. 'user'):

<msxsl:script language="Javascript" implements-prefix="user">
  function getLanguage() {
    ...
  }
</msxsl:script>

Finaly, in order to set the value of a variable to the result of calling
this function, you need to put the call to the function within the 'select'
attribute of an xsl:variable element, and use the namespace prefix you've
specified to indicate that it's a user-defined function:

<xsl:variable name="Language" select="user:getLanguage()" />

There's more about this in the MSXML SDK.

I hope that this 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.