[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: copy all attributes but one

Subject: Re: copy all attributes but one
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 18 Jan 2001 15:20:35 +0000
xsl copy all attributes
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.