RE: [xsl] testing attributes

Subject: RE: [xsl] testing attributes
From: Aaron Johnson <Aaron2.Johnson@xxxxxxxxx>
Date: Thu, 19 May 2005 11:37:13 +0100
Hi David...

Thanks very much for your reply, that is very useful!

I tried another way too...I added...

<!-- Courses Key -->
<xsl:key name="courseByRole" match="/user/courses/course" use="@role"/>

then...

<xsl:template match="courses">
<xsl:if  test="count(key('courseByRole','student')) &gt; 0">
	<h2>Course enrolments:</h2>
	<xsl:apply-templates select="key('courseByRole','student')"/>
</xsl:if>

...so have learnt two approaches this morning ; -)

...by the way, missing & well spotted 10 points to your team!

Aaron

......................................................................

Aaron Johnson
GUI / XSLT development
Academic Technologies Group [ATG]
University of the West of England
ext: 81051
t: 0117 3281051
www: http://atg.uwe.ac.uk/aaron
e: aaron2.johnson@xxxxxxxxx

SECURITY POLICY:

Please note that ATG will only accept
e-mail attachments in the following
formats:

.asp,.bin,.doc,.gif,.html,.jpg,.mdb,.png,
.psd,.shtml,.sdf,.sit,.xls,.xml,.xsd,.xsl,.zip,

......................................................................

This communication is intended solely
for the use of the individual(s) to whom
it is addressed. Any opinions presented
are those of the author and do not
necessarily represent the University of
the West of England, Bristol.

.......................................................................


-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: 19 May 2005 10:30
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] 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
________________________________________________________________________



This incoming email to UWE has been independently scanned for viruses
and any virus detected has been removed using McAfee anti-virus software


This email has been independently scanned for viruses and any virus software
has been removed using McAfee anti-virus software

Current Thread