[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Using keys in templates

Subject: Re: Using keys in templates
From: Nicolas Mailhot <Nicolas.Mailhot@xxxxxxxxxxx>
Date: Tue, 13 Jul 2004 17:34:54 +0200
nicolas key
Le mar, 13/07/2004 C  15:36 +0100, Jeni Tennison a C)crit :
> Hi Nicolas,
> 
> > 	I'm finding I'm using more and more constructs like :
> >
> > <xsl:key name="dists" match="/release/module/dist" use="@name"/>
> >
> > <xsl:template match="module/dist">
> >  <xsl:variable name="dist" select="@name"/>
> >  <xsl:if test="generate-id(.) = generate-id(key('dists',$dist))">
> >    something
> >  </xsl:if>
> > </xsl:template>
> >
> > 	Would it be possible to kill the if using a syntax like :
> >
> > <xsl:template match="module/dist[some test]" priority="1">
> > </xsl:template>
> >
> > <xsl:template match="module/dist" priority="0"/>
> 
> Yes -- you could use:
> 
>   match="module/dist[generate-id(.) =
>                      generate-id(key('dists', @name))]"
> 
> but it would probably be better to only select the <dist> elements
> that you want to process when you do the <xsl:apply-templates>, as in:
> 
> <xsl:template match="module">
>   <xsl:apply-templates
>     select="dist[generate-id(.) =
>                  generate-id(key('dists', @name))]" />
> </xsl:template>
> 
> <xsl:template match="dist">
>   <!-- this template only processed for the first dist element with
>        each particular name -->
>   ...
> </xsl:template>
> 
> Locating which template to use to process a node takes time, so you
> should try to apply templates to as small a set as possible rather
> than trying to find a template for every node, but only doing
> something with some of them.

Well, you're right but with priorities you can poison the default
template with an xml:message and detect when a node that isn't supposed
to be processed is.

Anyway, thanks for the advice !

-- 
Nicolas Mailhot

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.