Re: [xsl] Appl templates

Subject: Re: [xsl] Appl templates
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 25 Apr 2001 17:56:34 +0100
Hi Jason,

> I am having problems using apply templates all I want to return is
> the name ie Big insurance company, trouble is that I keeping getting
> everything returned.

Unless it's an error introduced while posting, I think your problem
lies in the fact that in your XML document, the policy element has a
name in lowercase whereas in your stylesheet:

>         <xsl:template match="Policy">
>                 <xsl:apply-templates select="Insurer[@ref='Insur']" "/>
>         </xsl:template>
You're matching policy with a capital 'P'.  XML is case sensitive, so
this kind of thing really matters.

However, even if you change that, you'll still get a lot of
information that you don't want.  The processor will take the Insurer
element and try to process it.  Since you don't have any templates
matching that element, it'll use the built in template, which looks

<xsl:template match="*|/">
   <xsl:apply-templates />

So it will apply templates to all its child nodes.  One of those is
the Insurer Name - that will match your other template:

>         <xsl:template match="Name" name="CoName">
>         <b>Company Name :</b> <xsl:value-of select="."/><br/>
>         </xsl:template>

So you'll get that information with 'Company Name :' added in front of
it.  However, there aren't any templates for the other children of the
Insurer element, so again they'll just the default template, and the
processing will recurse down the tree until you get to another
built-in template, which just outputs any text it finds:

<xsl:template match="text()">
   <xsl:value-of select="." />

If you don't want the text output by default, either add an empty
template to override the built-in template for text():

<xsl:template match="text()" />

Or only apply template to the Insurer Name in the first place:

<xsl:template match="policy">
   <xsl:apply-templates select="Insurer[@ref = 'Insur']/Name" />

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread