Subject: Re: [xsl] Using keys in templates From: Nicolas Mailhot <Nicolas.Mailhot@xxxxxxxxxxx> Date: Tue, 13 Jul 2004 17:34:54 +0200 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Using keys in templates, David Carlisle | Thread | RE: [xsl] Using keys in templates, Hansen, John |
Re: [xsl] implement attribute inher, Emmanouil Batsis | Date | Re: [xsl] Problem copying xhtml ele, M. David Peterson |
Month |