xsl-list
[Top] [All Lists]

Re: [xsl] The identity transform and attributes

2008-01-21 05:36:44
Andrew Welch wrote:
On 21/01/2008, David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:
It's certainly not intuitive that when you what to just change the
attribute's value you have to create a new attribute node
Intuition is a personal thing but I don't see why that's not
intuitive. xslt never updates nodes in place, so you always generate new
nodes.

Sure, but I meant along the lines of copy vs create... To update an
element's "value" you tend to copy it rather than create a new one.
To update an attribute's value I would say it's intuitive to try the
same approach, especially when the name and value are clearly separate
(to me!).

My intuition is the same as yours ;) I understand the reasoning behind the decisions, but I find myself doing a lot of extra work when I am dealing with attributes. I always have to remind myself whether it is an attribute node or an element node. Funnily enough, I don't have that same problem with text nodes or document nodes, somehow I find them (though different) more "intuitive".

Attributes are leaf nodes and work the same way as namespace nodes, and
PI nodes (that is they have a name and value but no children) element
nodes are the only ones to have name and children, document nodes have
children but no name, and comments and text nodes have a value but no
name.

I've been caught out before doing things like:

<xsl:template match="@*[not(self::foo)]">

...which doesn't work - you have to use name()

or the following (not tested), which has the advantage of not using unschema-aware strings:

  <xsl:template match="@*[not(../@foo is .)]

but that's hardly clearer

Again, I don't know why the self axis isn't available for attribute
nodes... any ideas?

Not 100% certain here, but I vaguely remember that self:: only works on elements and document nodes, not on other node types (i.e., a text node does not have a self:: axis, nor does a PI or a comment) . And an attribute's self:: axis would naturally be an attribute axis, which cannot hold.

Cheers,
-- Abel --

--~------------------------------------------------------------------
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>
--~--