Re: [xsl] copy all attributes but one

Subject: Re: [xsl] copy all attributes but one
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 18 Jan 2001 15:20:35 +0000
David C. wrote:
>  <xsl:copy-of select="attribute::*[not(local-name()='DoNotCopyAttribute'
> and namespace-name()='xxxx')]" />

but he meant:

<xsl:copy-of select="attribute::*[not(local-name()='DoNotCopyAttribute'
and namespace-uri()='xxxx')]" />
              ^^^

Actually, the vast majority of attributes are in the null namespace
because they don't have prefixes. If you know that the attribute you
want to filter out is unprefixed, then you can use local-name() and
test not(namespace-uri()):

<xsl:copy-of select="attribute::*[not(local-name()='DoNotCopyAttribute'
and not(namespace-uri())]" />

Or you can use name() directly:

<xsl:copy-of select="attribute::*[name() != 'DoNotCopyAttribute']" />

It's just that this is a bad habit to get into because when you come
up against prefixed attributes, like xlink:href, which *are* in a
particular namespace, then using the same pattern can cause Bad Things
to happen.  Namely, if I write this in my stylesheet:

<xsl:copy-of select="attribute::*[name() != 'xlink:href']" />

and then someone writes their XML source with 'xl' as a prefix
instead:

  xl:href="..."

Then because 'xl:href' isn't the same as 'xlink:href', the xl:href
attribute isn't filtered out.

Using local-name() and namespace-uri() gets around that but writing
out the URI for a namespace is long and tedious (I wish the XML Schema
writers recognised this!) so it's easier to use the prefix that you've
defined in your stylesheet to make the match, hence the generate-id()
and Kaysian intersection samples.
  
Cheers,

Jeni

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



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


Current Thread