xsl-list
[Top] [All Lists]

RE: [xsl] returning nodes which have a specific child

2009-07-03 09:06:47
 

-----Original Message-----
From: Wendell Piez [mailto:wapiez(_at_)mulberrytech(_dot_)com] 
...
 
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


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