xsl-list
[Top] [All Lists]

Re: [xsl] The identity transform and attributes

2008-01-21 07:12:35
...and we should perhaps re-learn the identity transform for 2.0 as:


<xsl:template match="element()">
  <xsl:copy>
      <xsl:apply-templates select="@*,node()"/>
  </xsl:copy>
</xsl:template>


<xsl:template match="attribute()|text()|comment()|processing-instruction()">
  <xsl:copy/>
</xsl:template>

...which might make attribute processing more intuitive for future xslt'ers.



Of course, if someone needs to process namespace nodes, the code above
would not help. In this case we need use:

   <xsl:element>
    <!-- then <xsl:copy-of> only selected namespace-nodes -->
    <!-- then (probably) placing other namespace nodes -->
    <!-- then do the rest of the processing -->
  </xsl:element>

-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play



On Jan 21, 2008 6:01 AM, Andrew Welch 
<andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> wrote:

On 21/01/2008, Abel Braaksma <abel(_dot_)online(_at_)xs4all(_dot_)nl> wrote:
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.

That describes it nicely.  Although I've been working with this for
years now, I still rarely get it right the first time around when
comes to attributes.

So for a bit of a summary - 2.0 makes things much simpler (as usual ):

To process all attributes except one:

@* except @foo

To check if the current attribute is a particular one:

test="self::attribute(foo)"

...and we should perhaps re-learn the identity transform for 2.0 as:


<xsl:template match="element()">
  <xsl:copy>
      <xsl:apply-templates select="@*,node()"/>
  </xsl:copy>
</xsl:template>


<xsl:template match="attribute()|text()|comment()|processing-instruction()">
  <xsl:copy/>
</xsl:template>

...which might make attribute processing more intuitive for future xslt'ers.



--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

--~------------------------------------------------------------------



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