Re: [xsl] match + default namespace

Subject: Re: [xsl] match + default namespace
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 16 Nov 2001 15:19:22 +0000
Hi Philippe,

> So, match="pre" is not the same than match="*[name() = 'pre']"
> Actually, this oddity disappears if I suppress the default namespace
> declared with the <table> element.
> Why ? This time, I have not really the true answer ...

XPath is namespace aware. When you say match="pre" or select="pre" you
are matching or selecting a 'pre' element *in no namespace*. To match
or select an element that is in a namespace, as the pre elements are
in your example, you have to declare the namespace in the stylesheet
with a prefix (e.g. 'abcd') and then use that prefix in your pattern
or expression to match or select the element (e.g. match="abcd:pre").

So try:

<xsl:stylesheet version="1.0"
    <xsl:template match="abcd:pre[@class='programlisting']">
        <pre class="programlisting">
             <xsl:call-template name="replace_first_tabs_on_all_lines">
                        <xsl:with-param name="codeSource" select="." />


You should be very careful using name() = 'pre' because if someone
used a different prefix in the source document, the test would not be
true any more (one of the points of namespaces being to allow you to
use whatever prefix you like with a namespace).

This is a common error that will hopefully be alleviated a little in
XSLT/XPath 2.0 by allowing people to determine the namespace
associated with unprefixed element names in patterns and expressions,
rather than having it fixed to no namespace as it is in XSLT/XPath

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread