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

RE: returning nodes which have a specific child

Subject: RE: returning nodes which have a specific child
From: "Michael Sokolov" <sokolov@xxxxxxxxxxxx>
Date: Fri, 3 Jul 2009 09:06:16 -0400
RE:  returning nodes which have a specific child
> -----Original Message-----
> From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx] 
...
 
> At 04:53 AM 7/2/2009, Michael Ludwig wrote:
> >I have an editor macro that produces the stylesheet skeleton plus 
> >identity template, as this is almost always the right starting point 
> >for a new stylesheet.
> 

...

> >Note that XSLT has built-in template rules that basically lose the 
> >markup and display the text only. Most of the time you'll want to 
> >supplant these by the identity template. Some people even think that 
> >the identity template should have been the built-in template rule.
> 
> And some don't. Some (like myself), think that might be a 
> useful option to allow -- at the cost, perhaps, of making 
> XSLT even more mysterious to beginners. :-)
> 
> >Bottom line, start with the identity template.
>

I'm w/Michael on this one, at least from the perspective of clarity and ease
of learning. The number one confusion for me when learning XSLT a couple of
years ago was the mysterious disappearance of all my tags, and the necessity
of learning, as almost the first step required to get anything useful done,
an arcane identity transformation:

>>  <xsl:template match="@*|node()"><!-- identity template -->
>>    <xsl:copy>
>>      <xsl:apply-templates select="@*|node()"/>
>>    </xsl:copy>
>>  </xsl:template> 

I would almost certainly have gotten a first working stylesheet more quickly
if the default were swapped.  And for the other case (ie when you want your
document turned in to text by default), the required rule to supplant the
copy-by-default is a lot simpler:

<xsl:template match="*">
   <xsl:apply-templates />
</xsl:template>

It's much easier to understand what this is doing.

I suppose a possible benefit of the current situation is that by grappling
with the identity transform, beginners are immediately forced to learn about
the difference between nodes, text, elements and attributes, including the
bizarre conceit that attribute *nodes* are not matched by the 'node()' test
(perhaps some other name would have been more appropriate?).  This is
required knowledge, so I guess the earlier swallowed the better?

Of course all this discussion seems besides the point and entirely academic
given the well-established precedents.  Can't go changing these defaults
now.  But that's no reason to try to provide post-hoc justifications,
either, IMO.

-Mike

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.