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

Re: testing attributes

Subject: Re: testing attributes
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 19 May 2005 10:29:50 +0100
xslt testing attributes
<xsl:when test="count(//course) &gt; 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 &amp; 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

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.