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

Subject: Re: [xsl] Apply-templates - how to omit top level element tags?
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Wed, 7 Sep 2005 15:01:59 -0500
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