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

Re: Newbie Question

Subject: Re: Newbie Question
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 17 May 2002 10:33:45 +0100
Re:  Newbie Question
Hi Roger,

> I really thought I was getting the hang of XSLT, until this. I know
> what's happening, the "catchall" template is outputting the value of
> the elements it see's. What I don't understand is why?

You're running foul of the built-in templates in XSLT, specifically
the one that looks like:

<xsl:template match="text()">
  <xsl:value-of select="." />
</xsl:template>

This template means that unless you have an overriding template,
whenever you apply templates to a text node, you get the value of that
text node.

You're applying templates to the text nodes within most of your
elements, because the template you have for most elements is:

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

which is the same as:

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

and tells the processor to apply templates to all the child nodes of
each element it finds. (By the way, there's a template just like this
built-in to XSLT; if you left out this template, your stylesheet would
behave in exactly the same way.)

The best way to prevent the text nodes that you're not interested in
from being shown is to not apply templates to them in the first place.
You could change your template so that it only applies templates to
child elements, as follows:

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

Alternatively, you could override the built-in template for text nodes
so that you don't emit anything when you find them:

<xsl:template match="text()" />

The former solution is better -- it gives the processor less work to
do because it doesn't have to figure out what template to apply to the
text nodes, and it means that you don't have to worry about what
happens when you *do* want to apply templates to text nodes directly.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


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.