Subject: Re: [xsl] testing attributes From: David Carlisle <davidc@xxxxxxxxx> Date: Thu, 19 May 2005 10:29:50 +0100 |
<xsl:when test="count(//course) > 0"> Tha's a very expensive test it causes the whole document to be searched to arbitray depth to count all the course elements and then you throw it all away as you don't really need them. If you are lucky your system (I think saxon does this) will spot this idiom and change it to <xsl:when test="//course"> and stop the search when it finds the first course. I'd use a variable here something like <xsl:variable name="c" select="//course"/> If you can replace //course by something else eg /courses/course it might be a lot more efficient (// is essentially a costly operation, although the exact details are complicated due to the fact that because it is easy to spot and very expensive to do, XSLT engines are quite likely to have optimised code for this case so rewrite it to something more efficient) <xsl:variable name="c" select="//course"/> <xsl:choose> <xsl:when test="$c"> <h2>Courses</h2> <xsl:apply-templates select="$c"/> </xsl:when> <xsl:otherwise> <h2>You are not currently participating in any any courses</h2> </xsl:otherwise> </xsl:choose> <xsl:template match="courses"> <xsl:apply-templates select="course"/> </xsl:template> This template is unused as you never apply templates to courses elements <xsl:template match="course"> <li> <a href="{$host}{url}amp;useCas=1" target="_blank"><xsl:value-of ^^ you want & here select="title"/></a> Here I'd have do something like <xsl:apply-templates select="@role"/> </li> </xsl:template> <xsl:template match="@role[.='mathematics']">fun fun fun</xsl:template> <xsl:template match="@role[.='latin']">hmmm</xsl:template> .... ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] testing attributes, Aaron Johnson | Thread | RE: [xsl] testing attributes, Michael Kay |
[xsl] testing attributes, Aaron Johnson | Date | RE: [xsl] testing attributes, Aaron Johnson |
Month |