Re: [xsl] copy attributes, except some
2009-10-29 21:03:03
Hi Wendell,
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=""
name4=""/></xsl:variable>
I can now declare:
<xsl:variable name="excepted-attributes"
select="$dummy-attributes//@*/node-name(.)"/>
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
insight.
Cheers,
ac
ac,
At 02:37 AM 10/29/2009, you wrote:
Hi,
Sorry for noise again, but David did provide a possibly better option
as in:
<xsl:copy-of select="@* except (attribute(name1), attribute(name2),
attribute(name3), attribute(name4))"/>
Also (syntax errors aside), if you wanted to drive this from the top:
<xsl:variable name="excepted-attributes" select="//@name1 | //@name2 |
//@name3"/>
... and then ...
<xsl:copy-of select="@* except $excepted-attributes"/>
Cheers,
Wendell
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
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
======================================================================
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
|
|