[xsl] How to declare a namespace

Subject: [xsl] How to declare a namespace
From: "frank Stein" <freeposte@xxxxxxxxxxx>
Date: Tue, 30 Jan 2001 09:13:05

Hi Jeni, many thanks to You for this wonderful answer below. I'm using the Internet Explorer 5.0 with the msxml3 XSL parser version patch.

I've followed your instructions and I've declared a couple of functions
within the msxsl:script element but I did not declare the 'msxsl' namespace(urn:schemas-microsoft-com:xslt) and my own 'foo' namespace.


While the interpretation the IE.5 outputs the following error :

"Reference to undeclared namespace prefix: 'msxsl'. Error processing resource 'file:///D:/Ovide/test.xsl'. Line 10, Position 66

<msxsl:SCRIPT language="javascript" implements-prefix="foo"><![CDATA[
-----------------------------------------------------------------^"

Could You please explain me how and where to declare these two namespaces ?

Thank-You again Jeni.

Ovide

From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Reply-To: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
To: "frank Stein" <freeposte@xxxxxxxxxxx>
CC: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:
Date: Mon, 29 Jan 2001 21:19:12 +0000

Hi Frank,

> please, is there any way to affect an xml variable with the output
> return of a JavaScript function ?

Yes, but be aware that Javascript isn't incorporated into XSLT until
XSLT 1.1 or unless you're using MSXML.  The first thing that you need
to do is to declare the function within an msxsl:script element:

<msxsl:script language="javascript"
              implements-prefix="foo">
   function retrieveData() {
      return true;
   }
</msxsl:script>

In order to do this, you need to declare the 'msxsl' namespace
(urn:schemas-microsoft-com:xslt) and your own 'foo' namespace. The
'msxsl' namespace needs to be declared as an extension element prefix
(using the extension-element-prefixes attribute on xsl:stylesheet) and
the 'foo' namespace should be excluded from your result tree (using
the exclude-result-prefixes or extension-element-prefixes attribute on
xsl:stylesheet).

Once you've declared the Javascript functions like this, you can call
them within any XPath expression using, e.g.:

foo:retrieveData()

So, to set $my_var to have the value returned by the function, use:

<xsl:variable name="my_var" select="foo:retrieveData()" />

There's nothing in XSLT that interprets the content of an element as
something to run: calls to functions are *always* in attribute values.

I hope that helps,

Jeni

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



_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


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



Current Thread