the useless name() function (was Re: Using the not function)

Subject: the useless name() function (was Re: Using the not function)
From: "Mark D. Anderson" <mda@xxxxxxxxxxxxxx>
Date: Mon, 17 Jan 2000 09:43:53 -0800
--On Monday, January 17, 2000 11:23 AM +0000 David Carlisle <davidc@xxxxxxxxx> wrote:
> No, name() gives the literal prefixed name from the source.

and Michael Kay agrees:
>Generally speaking, it's best to avoid testing the result of the name()
>function, because two XML documents that are equivalent except for their
>choice of namespace prefixes will give different answers. Using
>"not(self::element3)" is safer.

Damn, I wasn't aware of this.

So:

- if you have an expanded name which is a literal, and you want to
match only on that name in that namespace, then use self::
   xmlns:myprefix = urn:some-uri
   ...
   [self::myprefix:el] <!-- if desired node has a namespace which myprefix expands to -->
   [self::el] <!-- if desired node has no namespace -->

- if you want to match any element which has a particular local name,
regardless of namespace, use local-name():
   [local-name() = 'el']

- if you want to match a local name against a variable, that is easy:
   <xsl:variable name="local_elname" select="'el'"/>
   ...
   [local-name() = $local_elname]

- if you want to match an expanded name against a variable, that is hard:
   <xsl:variable name="local_elname" select="'el'"/>
   <xsl:variable name="ns_el" select="'urn:some-uri'"/>
   ...
   [local-name() = $local_elname and namespace-uri() = $ns_el]

- if you want to match qnames, that is easy but not what you want:
   <xsl:variable name="q_elname" select="'myprefix:el'"/>
   ...
   [name() = $q_elname]

Did i get that right?

-mda


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


Current Thread