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

Re: XSLT: Are XML Comments parseable?

Subject: Re: XSLT: Are XML Comments parseable?
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Tue, 20 Sep 2005 14:03:01 +0100
andrew welch of pa
It's because of a thing called the 'default template' which kicks in
when you haven't specified a template to match the current node.

When the XML is transformed, the root matching template is the first
to be applied.  If you haven't provided one, the default one is used,
which looks like this:

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

The <xsl:apply-templates/> instruction applies templates to the
comment and to the <fruit> element.  You have a template that matches
the comment, but not one for the <fruit> element, so the default
template is used again.  The default template for a text node copies
it to the output, which is why you see 'apple'.

The two choices here are to provide a root matching template and only
apply-templates to the comment, eg:

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

This way the <fruit> element never gets processed and so it wont
appear in your output.

The other way is to provide a template for <fruit> that doesn't ouput
anything:

<xsl:template match="fruit"/>

This means this template will be used instead of the default template,
and as it does nothing you won't get anything in the output.

The first way only selects the things you want to process.  The second
way processes everything but uses 'no-op' templates to suppress
unwanted output.

More info can be found at Dave Pawson's FAQ:
http://www.dpawson.co.uk/xsl/sect2/defaultrule.html

cheers
andrew

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.