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

Re: Copy all attributes except except some

Subject: Re: Copy all attributes except except some
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 10 Jun 2014 23:49:31 -0000
Re:  Copy all attributes except except some
On 11-6-2014 1:05, Philipp Kursawe phil.kursawe@xxxxxxxxx wrote:
> I am using:
> <xsl:copy-of select="@*[local-name() != 'signed']"/>

Because of the way != works, this will usually give you all attributes
regardless.

> I assume I have to make a long list of "or local-name() != 'otherAtt'"
> to exclude all my attributes that should not be copied over. Or is
> there a smarter way to just define a list of attributes that are not
> copied?

There are many ways. "Long list" sounds to me that you want to configure
it somewhere explicitly, or look for a pattern in the local-name. Also,
in most XML I have seen, attributes are in no-namespace, but I haven't
seen your input so I'm not sure. I would use the except keyword, which
works just the way you expect it to work:

<xsl:copy-of select="@* except (@signed, @unsigned)"/>

Or if you cannot use nametests, you can continue to using local-name(),
but you should reverse the test and use '=' on a sequence, instead of
'!=', like this:

<xsl:copy-of select="@*[not(local-name() = ('signed', 'unsigned'))]"/>

Though, if you do have attributes in namespaces and if you do know the
names you want to exclude, I can advice you to use nametests instead.
Consider your input looks like:

<foo x:signed="true" y:signed="false" z:signed="always" />

And you the prefixes x, y, z are each bound to different namespaces, you
will remove too many attributes if you use local-name(). Instead, write
it as follows:

<xsl:copy-of select="@* except (@z:signed, @y:signed)"/>

which will leave x:signed in place and remove the rest.

There are many more ways in XSLT to tackle this issue. To help you
better for your situation, it would help us help you if you show us a
(small, but complete) sample of your input data.

Cheers,

Abel Braaksma
Exselt XSLT 3.0 streaming processor
http://exselt.net

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.