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

Re: copy attributes, except some

Subject: Re: copy attributes, except some
From: ac <ac@xxxxxxxxxxxxx>
Date: Thu, 29 Oct 2009 21:02:28 -0400
Re:  copy attributes
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@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 ======================================================================

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.