Re: [xsl] Streamlining XSL and transform performance (how does it actually work?)

Subject: Re: [xsl] Streamlining XSL and transform performance (how does it actually work?)
From: Kevin Jones <kjones@xxxxxxxxxxx>
Date: Mon, 22 Mar 2004 09:31:29 +0000
On Friday 19 March 2004 16:30, Julian Voelcker wrote:
>
> OK, a couple more questions if you can bear it...
>
> Where we have..
>
> <XSL:template match="AnswerSet">
>         <xsl:apply-templates
> select="Answer[@name='ticdesc']"/> </xsl:template>
> <xsl:template match="Answer[@name='ticdesc']">
>         <p><xsl:value-of select="TextValue"/></p>
> </xsl:template>>
>
> There are going to be a lot of instances when I want to be
> able to 'extract' a specific value like the value of ticdesc. 
> Is there any way of making the template more versatile so that
> the name ticdesc is passed to is when the template is applied?

Unfortunatly you can't use variables in match patterns but there 
is an alternative in the form of generic templates 
(http://www.dpawson.co.uk/xsl/sect2/generic.html). Here is a 
quick example.

<sarvega:dispatchtable>
    <ticdesc name='ticdesc'/>
     <female name='Female'/>
     <abgrbefore name='ABGRBefore'/>
</sarvega:dispatchtable>

<xsl:template match="/">
    <xsl:apply-templates 
select="document('')/xsl:stylesheet/sarvega:dispatchtable/*[@name='ticdesc']"/>
</xsl:template>

<xsl:template match="ticdesc|female">
     <xsl:copy-of select="."/>
</xsl:template>

Note that in the select clause in the apply templates I have 
hardcoded 'ticdesc' but you can use a variable here. 

>
> Also, going along the same lines, is it possible to set and
> read variables within the XSL file?
>

This is a very frequently asked question, 
http://www.dpawson.co.uk/xsl/sect2/N8090.html should help.

Kev.

Current Thread