[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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 21:11:12 -0400

Well, the solution was simple, use:

> > > ==========================================
> > > <h1><xsl:apply-templates select="Name/node()"/></h1>
> > > ==========================================

Instead of either of these:

> > > ==========================================
> > > <h1><xsl:apply-templates select="Name"/></h1>
> > > <h1><xsl:value-of select="Name"/></h1>
> > > ==========================================

Unfortunately, I still don't grok the difference between:

	*
	.
	node()

What I'd like to see is example showing all the potential differentuse cases
of each of the three and what they output, but I can't find that concisely in
any of the books or websites I've looked at.  I guess I'll just have to set
aside several hours and do it myself.

-Mike



-----Original Message-----
From: Mike Schinkel [mailto:mikes@xxxxxxxxx]
Sent: Wednesday, September 07, 2005 8:05 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Apply-templates - how to omit top level element tags?

Thanks.  It is not a namespace problem.  Your answers does work, thanks, but
only in the special case of:

	<Name>My Title<myns:TrademarkSymbol></Name>

But not in the generic where the trademark symbol is not at the end:

	<Name>My Title<myns:TrademarkSymbol> has more words</Name>

The latter case displays:

	My Title has more words(tm)

So if I use what you provided, I'll be leaving a land mine in my XSL that will
cause future (possibly at first undetected) problems.

-Mike

-----Original Message-----
From: Antsnio Mota [mailto:amsmota@xxxxxxxxx]
Sent: Wednesday, September 07, 2005 7:35 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Apply-templates - how to omit top level element tags?

If the problem is in the use of namespaces, i'm not the guy to help you.
However, in case it's not, try to use

         <xsl:template match="Name"  mode="cover-page-title">
                 <xsl:value-of select="."/>
                 <xsl:apply-templates select="*"/>
         </xsl:template>

so you can catch the <xsl:template match="myns:TrademarkSymbol">

But i'm not a expert, so if this doesn't work you better wait for tomorrow
answers...

On 9/8/05, Mike Schinkel <mikes@xxxxxxxxx> wrote:
> Thanks for your help thus far.  However, that doesn't seem to be working.
>
>
> Here is a fragment of the XSL code I have
>
>         <h1><xsl:apply-templates select="Name"
> mode="cover-page-title"/></h1>
>
> And here is the template I have defined
>
>         <xsl:template match="Name"  mode="cover-page-title">
>                 <xsl:value-of select="."/>
>         </xsl:template>
>
> And
>         <xsl:variable name="trademark-symbol">&#8482;</xsl:variable>
>         <xsl:template match="myns:TrademarkSymbol"
myns="myns:TrademarkSymbol">
>                 <xsl:value-of select="$trademark-symbol"/>
>         </xsl:template>
>
> In my XML document document I have:
>
>         <Name>My Title<myns:TrademarkSymbol/></Name>
>
> And my output is still:
>
>         <h1>My Title</h1>
>
> Instead of what I want:
>
>         <h1>My Title(tm)</h1>
>
> I've tried lots of different things, but each time I just get either
>
>         <h1>My Title</h1>
> Or
>         <h1></h1>
>
> -Mike
>
>
> -----Original Message-----
> From: Antsnio Mota [mailto:amsmota@xxxxxxxxx]
> Sent: Wednesday, September 07, 2005 4:01 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Apply-templates - how to omit top level element tags?
>
> Then you use modes.
>
> > <xsl:apply-templates select="Name" mode="PutH1"/>
> > <xsl:apply-templates select="Name" mode="PutSomeOtherThing"/>
>
> > <xsl:template match="Name" mode="PutH1">
> >    <h1>
> >       <xsl:value-of select="."/>
> >    </h1>
> > </xsl:template>
>
> > <xsl:template match="Name" mode="PutSomeOtherThing">
> >    <h2><b>
> >       <xsl:value-of select="."/>
> >    </b></h2>
> > </xsl:template>
>
> 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?
> >
> > -Mike
> >
> > -----Original Message-----
> > From: Antsnio Mota [mailto:amsmota@xxxxxxxxx]
> > Sent: Wednesday, September 07, 2005 3:44 PM
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: Re: [xsl] Apply-templates - how to omit top level element tags?
> >
> > You should use
> > <h1><xsl:apply-templates select="Name"/></h1>
> >
> > and then a  template for Name
> >
> > <xsl:template match="Name">
> >   <xsl:value-of select="."/>
> > </xsl:template>
> >
> > or better
> >
> > <xsl:apply-templates select="Name"/> <xsl:template match="Name">
> >    <h1>
> >       <xsl:value-of select="."/>
> >    </h1>
> > </xsl:template>
> >
> >
> >
> > On 9/7/05, Mike Schinkel <mikes@xxxxxxxxx> wrote:
> > > To all:
> > >
> > > I'm trying to figure out how to use <xsl:apply-templates> (or
> > > anything
> > > else) to get the right output:
> > >
> > > I've got an XML file and am generated XHTML.
> > >
> > > In my XSL file, I have the following variable and template:
> > >
> > > ==========================================
> > > <xsl:variable name="trademark-symbol">&#8482;</xsl:variable>
> > > <xsl:template match="htsg:TrademarkSymbol" name="htsg:TrademarkSymbol">
> > >         <xsl:value-of select="$trademark-symbol"/> </xsl:template>
> > > ==========================================
> > >
> > > In my XML file, I have a fragment that looks like this:
> > >
> > > ==========================================
> > > <Name>This is the Title of the
> > > Publication<myns:TrademarkSymbol/></Name>
> > > ==========================================
> > >
> > > I want to generate output that looks like this:
> > >
> > > ==========================================
> > > <h1>This is the Title of the Publication(tm)</h1>
> > > ==========================================
> > >
> > > However, if I use this in my XSL:
> > >
> > > ==========================================
> > > <h1><xsl:apply-templates select="Name"/></h1>
> > > ==========================================
> > >
> > > I get the following that includes the <Name> element:
> > >
> > > ==========================================
> > > <h1><Name>This is the Title of the Publication(tm)</Name></h1>
> > > ==========================================
> > >
> > > When I try instead to use this:
> > >
> > > ==========================================
> > > <h1><xsl:value-of select="Name/text()"/></h1>
> > > ==========================================
> > >
> > > I just get this w/o the trademark:
> > >
> > > ==========================================
> > > <h1>This is the Title of the Publication</h1>
> > > ==========================================
> > >
> > > Again, this is what I want to generate as output:
> > >
> > > ==========================================
> > > <h1>This is the Title of the Publication(tm)</h1>
> > > ==========================================
> > >
> > >
> > > I look forward and appreciate any suggestions, even those that
> > > might have be taking a completely different route, but I also
> > > really want to understand how to accomplish this using
> > > apply-templates or value-of or whatever.
> > >
> > > Thanks in advance for your help.
> > >
> > > -Mike Schinkel
> > > Publisher - How-To-Select(tm) Guides
> > > http://www.howtoselectguides.com/
> > > mailto:mikes@xxxxxxxxxxxxxxxxxxxxx
> > > 404-591-5701 (V)
> > > 404-591-5731 (F)


Current Thread
Keywords