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

Re: Apply-templates - how to omit top level element ta

Subject: Re: Apply-templates - how to omit top level element tags?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 08 Sep 2005 18:43:54 -0400
persnickety templates
Mike,

At 06:06 PM 9/8/2005, David wrote:

                                <h1>
                                        <!-- THIS IS WHAT I NEEDED -->
                                        <xsl:apply-templates
select="Name/node()"/>
                                </h1>


That works but makes things look a lot more complicated than need be. You probably just want to replace all that by <xsl:apply-templates select="Name"/>

and have
<xsl:template match="Guide/Name">
 <h1><xsl:apply-templates/></h1>
</xsl:template>

That's probably a more natural xslt coding style.

... and it would implicitly override your identity template (the one matching "@*|node()", which would get rid of that problem -- so your stylesheet would "just work" had you had this template.


OTOH, you couldn't have known this. Another vital detail in the XSLT processing model: how the processor decides among templates when more than one template (oops: "template rule"; see below) matches a given node. In this case, a template that matches "node()" (any node) and one that matches "Guide/Name" (a name element child of a Guide element) both would match your Name. The processor sees this and chooses the latter as a "better match". (The reason: the rules for template matching assign it a priority of 1, while the template matching "node()" has a priority of -0.5....)

BTW, a "template rule" is that construct we generally call a "template". No one knows this or bothers to observe it, but "templates" are the *content* of template rules ... templates also appear inside xsl:for-each instructions.

I'm a secularist too, but I'm willing to be just as persnickety as any religionist if it helps get the job done. Not persnickety for its own sake, mind you. :-)

Cheers,
Wendell


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

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.