Subject: Re: [xsl] Performance Issue (if any?) From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Mon, 14 May 2001 10:51:43 +0100 |
Hi Robin, > Just wondering if there are any performance issues and/or preferred > methods of deciding when it is best to use <xsl:call-template > name="whatever"> over <xsl:template match="somenode" > mode="withmode">. In this case, I only need to make 2 passes (so > far!), so is there any difference really? In answer to the general question, it's probably slightly easier for a processor to find a named template than a matching template, so it might be slightly more efficient to use a named one, but not so much that it's worthwhile at the expense of complicating your stylesheet. In this case, the content of the template that you're talking about has no reliance on the current node when it's called - it collects all the employees together and creates a card for each of them. I would therefore make it a named template (especially as you might accidentally apply it to more than one employee, which mean it created cards for all the employees multiple times). Personally, though, I wouldn't have the xsl:for-each that you have, and instead I'd work down the hierarchy to build up the cards for each employee. The top-level template would look like: <xsl:template match="employeehierarchy"> <wml> <card id="employees"> <p>Employees</p> <p><xsl:apply-templates /></p> </card> <xsl:apply-templates mode="makeCards"/> </wml> </xsl:template> The employee-matching template in the default mode would look roughly the same as it does at the moment: <xsl:template match="employee"> <!--Build the wml cards--> <!--Build the card that lists the employees--> <a href="#{emplast}"><xsl:value-of select="emplast"/></a> <xsl:value-of select="concat(', ', empfirst, ' ', empmiddle)" /> <br/> <xsl:apply-templates select="employees" /> </xsl:template> [Changes here were to use an attribute value template rather than xsl:attribute, to use xsl:value-of to create the string (just to save space), and to apply templates to employees and let the built-in templates do their work.] Then I'd have an employee-matching template in makeCards mode that looked like, the following. This works through the employees recursively, making a card for each of them, a lot like the template above, rather than iterating over them using xsl:for-each: <!--Build the cards that list each individual employee--> <xsl:template match="employee" mode="makeCards"> <card id="{emplast}"> <p> <xsl:value-of select="concat(emptitle, ' ', empfirst, ' ', emplast)" /> <br/> </p> <p>Position:<br/> <xsl:value-of select="empposition"/> <br/> </p> <p>Job Description:<br/> <xsl:value-of select="empdescription"/> <br/> </p> <p>Extension:<br/> <xsl:value-of select="empextension"/> <br/> </p> </card> <xsl:apply-templates select="employees" mode="makeCards" /> </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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Performance Issue (if any?), Robin Samways | Thread | RE: [xsl] Performance Issue (if any, Robin Samways |
[xsl] <xsl:output doctype-system="n, Stephane . Le-Deaut | Date | Re: [xsl] Nested sections from flat, Jeni Tennison |
Month |