[XSL-LIST Mailing List Archive Home]
Re: [xsl] copy attributes, except some
Subject: Re: [xsl] copy attributes, except some|
From: ac <ac@xxxxxxxxxxxxx>
Date: Thu, 29 Oct 2009 21:02:28 -0400
True. The thing that still bothers me with this is that since nodes and
content are compared, a variable like $excepted-attributes has to be
defined for every attribute group, for every tree/subtree that may get
copied which is getting to be quite an overhead here. The situation is
more or less the same for the attribute() approach. Comparing attribute
names is really what I require but is trickier in a namespace safe way.
Consequently, by first declaring a variable with a "dummy" set of
attributes to exclude, like
<xsl:variable name="dummy-attributes"><xx name1="" name2="" name3=""
I can now declare:
and later use:
<xsl:copy-of select="@*[not(node-name(.) = $excepted-attributes)]"/>
on as many trees as I need, bringing the variable overhead down to two
per excepted attribute set, independently of the number of tree/subtree
that need copying, which is a lot in this case.
Also note that the example here copies attributes from the context node
which implies, especially with many trees/subtrees and many excluded
attributes that you would want to use a lot of <xsl:for-each
select="$this-tree-or-subtree"> elements to set those context nodes.
With an attribute name-based approach one can also spare most of these
context setting instructions, just simply using the tree variable
reference once, per tree. Again, it seems, quite a saving in a setting
with many trees/subtrees.
The solution still does not seem perfectly elegant, especially as it is
a little twisted, but it seems like the best possible, and it works.
Mind you, in a context where elements can have dynamic attribute sets
from a wide potential range, from multiple namespaces, which I think
should be casual with XML, it may be interesting to consider how this
could be made more elegant.
It works for now and I thank you, and everyone who contributed, for the
At 02:37 AM 10/29/2009, you wrote:
Sorry for noise again, but David did provide a possibly better option
<xsl:copy-of select="@* except (attribute(name1), attribute(name2),
Also (syntax errors aside), if you wanted to drive this from the top:
<xsl:variable name="excepted-attributes" select="//@name1 | //@name2 |
... and then ...
<xsl:copy-of select="@* except $excepted-attributes"/>
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
Mulberry Technologies: A Consultancy Specializing in SGML and XML