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

Subject: RE: [xsl] Apply-templates - how to omit top level element tags?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 08 Sep 2005 14:22:40 -0400

At 07:32 PM 9/7/2005, you wrote:
Also, why is it not possible to be able to output:


When you start with


It is possible.

Where the XSL has this:

<xsl:template match="myns:MyX">XXX</xsl:template>

I either get:


Or just:


But not what I want, which is:


You haven't shown us the template matching "Name".

Combined with your template above, this template

<xsl:template match="Name">

will result in


but this template

<xsl:template match="Name">

will result in



<xsl:template match="Name">

will result in


Why do I have to write a specific template to accomplish this?  In the
case above I want to output the value contained in <Name> that way only
once, but I also want the write of the XML to be able to embed other
references into it that I can parse with apply-templates.

As near as I can understand it, you are asking the XSLT to do something it does quite naturally. But it's hard to determine what your actual criteria are from this description.

Having to create a template for a single case is like having to write a
function in Java called Add37(x) simply to add 37 to the variable "x" in
only one place in the code.  Why can't I just do it inline rather than
have to worry about logic in two places and also worry about potential
sideaffects or name collisions? Is it because XSL simply doesn't provide
such a capability?

Again, I'm not sure of the actual problem here. XSLT provides a "for-each" instruction to allow you to avoid writing templates that are only used once, in a single context. But I suspect that's actually a red herring in your case.

If the problem isn't yet solved, could we trouble you to repost a demonstration?


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