Re: default template (was:RE: [xsl] text() and not())

Subject: Re: default template (was:RE: [xsl] text() and not())
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 08 Jan 2002 14:59:24 -0500
Andrew,

Also, following David's example (below), if inside x you only want to process a, an <xsl:apply-templates select="a"/> is very effective. Combining this with the empty template approach David shows, and you almost never have to suppress text nodes.

Getting rid of text you don't want by overriding the default template matching "text()" seems like an effective expedient until you start discovering how often you need to override your own new default. I think that's the situation you're in.

One gotcha to watch out for is that the expression <xsl:value-of select="text()"/> does not get you the value of all text node children of the current node, but only of the first one. So xsl:value-of is less useful than it might first appear, and has to be used with this limitation in mind.

Cheers,
Wendell

At 10:57 AM 1/8/02, David wrote:
If you have an element <x> that has all sorts of children that yuu don't
want to process, it is more nomal to have a template for x which does
not call apply-templates and so naturally doesn't process its children
than it is to use a template for x that does use apply templates and
then make templates for each child that does nothing.

If only some of x's children need zapping, suppose you have

<x>
<a>a text</a>
<b>b text</b>
<c>c text</c>
</x>

and yoy want b to go, it is more natural to say

<xsl:template match="b"/>

ie have an empty template for b than to allow b to have the default
template which would process its text child, and then have

<xsl:template match="text()[parent::b]"/>

David


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


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread