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: Wed, 7 Sep 2005 19:32:01 -0400
>> Plenty of ways to do this and it's hard to tell advise any particular
method without knowing more about your XML.templates and your style.

Thanks.  What do you mean by "style?"  Can you quantify this, or is it
just a subjective thing?

Also, why is it not possible to be able to output:

	FooXXX

When you start with

	<Name>Foo<myns:MyX></Name>

Where the XSL has this:

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

I either get:

	<Name>FooXXX</Name>

Or just:

	Foo

But not what I want, which is:

	FooXXX

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.

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?

Thanks in advance for your help.

-Mike



-Mike

-----Original Message-----
From: Jon Gorman [mailto:jonathan.gorman@xxxxxxxxx]
Sent: Wednesday, September 07, 2005 4:02 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Apply-templates - how to omit top level element tags?

On 9/7/05, Mike Schinkel <mikes@xxxxxxxxx> wrote:
> Thanks.  Question, I use "Name" in many contexts in my XML.  How can I
do this when I don't always want "Name" to be handled that way?
>

Check out modes, have choose statements, or be more selective in your
apply-templates selectiong.  Plenty of ways to do this and it's hard to
tell advise any particular method without knowing more about your
XML.templates and your style.  Lets say you have Name appear in two
places, in a description of the company and when the company is actually
used in some text...

so

<description>
<Name>some name</Name>
more nodes
</description>
<text>
whaaa wawa <Name>some name</Name>
</text>
could have two templates (code not tested)

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

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

<xsl:template match="Name" mode="descript"> <h1><xsl:value-of select="."
/></h1> </xsl:template>

<xsl:template match="Name" mode="text">
<span class="name"><xsl:value-of select="." /></span> </xsl:template>


Jon Gorman

Current Thread