Re: Using keys in templates
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
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format