Re: [xsl] How to declare a namespace

Subject: Re: [xsl] How to declare a namespace
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 31 Jan 2001 12:07:53 +0000
Hi Frank,

> 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.
[snip]
> Could You please explain me how and where to declare these two namespaces ?

You declare namespaces with namespace declarations, which are
attributes of the form:

  xmlns:prefix="namespace-URI"

So, for example, a namespace declaration for the MSXML namespace looks
like:

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

You can give any prefix that you want (msxsl, ms, m or whatever) as
long as you're not using that prefix for another namespace. The
namespace URI is fixed, though - that's what the processor uses to
identify whether a particular element/function is in a particular
namespace.

Your 'foo' namespace should be a URI that you can guarantee no one
else will use, perhaps something like:

  xmlns:my="urn:freeposte@xxxxxxxxxxx:2001"

It doesn't particularly matter what it is - a lot of people use URLs,
but that can be a bit tricky if you don't have a personal domain name.

You should place these namespace declarations on an element that
contains *all* the places where you want to use that namespace
declaration.  Most often in XSLT stylesheets, this will be the
xsl:stylesheet element because it contains everything.  So your
stylesheet will look something like:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:my="urn:freeposte@xxxxxxxxxxx:2001"
                extension-element-prefixes="msxsl"
                exclude-result-prefixes="my">

<msxsl:script language="javascript"
              implements-prefix="my">
  ...
</msxsl:script>

...

</xsl:stylesheet>

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