Re: [xsl] template pattern does not get matched properly with xmlns declaration

Subject: Re: [xsl] template pattern does not get matched properly with xmlns declaration
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 18 Jan 2001 16:27:37 +0000
Hi Helen,

> However after I removed xmlns declaration(i.e xmlns="
> http://www.ipdr.org/namespaces/ipdr"; part) from IPDRDoc element
> in test.xml, everything is just working fine. I have no idea what's wrong with
> the xml/xsl test files.

The fact that taking the default namespace declaration out changed
things indicates that it's a namespace issue.  Because of the default
namespace declaration, all the elements that don't have a prefix are
placed in the 'http://www.ipdr.org/namespaces/ipdr' (IPDR) namespace.

Now, in your stylesheet you match against IPDRDoc elements but don't
specify a prefix for them.  If you don't specify a prefix when you're
matching/selecting an element, then it assumes you mean an element in
the *null* namespace.  The IPDRDoc element in the IPDR namespace
isn't an IPDRDoc element in the null namespace, so it doesn't match
that template, and the built in templates are used all the way
through.

To get around this, you need to declare the IPDR namespace (with a
prefix) within the XSLT stylesheet. Something like:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:ipdr="http://www.ipdr.org/namespaces/ipdr";>
...
</xsl:stylesheet>

Then, whenever you want to refer to an element in that namespace, you
have to use the prefix you've assigned to it (ipdr in this case)
within the name.  For example, the match pattern for the template
should be:

<xsl:template match="ipdr:IPDRDoc">
   ...
</xsl:template>

By the way, space is preserved within all elements in your source by
default, so:

<xsl:preserve-space elements="text" />

won't have any effect unless you also tell it to strip spaces for the
'text' element, perhaps by telling it to strip spaces for *all*
elements through something like:

<xsl:strip-space elements="*" />

I don't see any 'text' elements in your source, though, so I'm not
exactly sure why you've got this instruction in the first place?

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