This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Appl templates


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
like:

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

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="." />
</xsl:template>

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" />
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]