RE: [xsl] Apply-templates - how to omit top level element tags?

Subject: RE: [xsl] Apply-templates - how to omit top level element tags?
From: "Mike Schinkel" <mikes@xxxxxxxxx>
Date: Thu, 8 Sep 2005 19:23:23 -0400
What you quoted mixed part of my example and part of other people's

Basically, at this point, I'm pretty sure <xsl:apply-templates
select="Name/node()/> is exactly what I wanted.  Using

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

Won't work for me because, in other contexts, I want "Guide/Name" to
output something different, such as being surrounded by "<title>" tags
instead of "<h1>" tags.  So rather than have to create template rules
with different named modes that are each used on one and only one
context for each and every different context, I just inline
<xsl:apply-templates select="Name/node()/> where I need it, which does
exactly what I want, when I want it.  That's pull if I'm not mistaken.

OTOH, I use push to allow my content authors to use elements like macros
to get the trademark symbol and generated items like lists of products
generated by XSL but incorporated into their narrative.

Isn't that how it's suppose to work?

Maybe I'm doing it all wrong, but at this point it's working for me
exactly as I needed.


-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
Sent: Thursday, September 08, 2005 6:44 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Apply-templates - how to omit top level element tags?


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

>                                 <h1>
>                                         <!-- THIS IS WHAT I NEEDED -->
>                                         <xsl:apply-templates
>                                 </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
>and have
><xsl:template match="Guide/Name">
>  <h1><xsl:apply-templates/></h1>
>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

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. :-)


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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