This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: conditional template matching & failure
- From: Jarno dot Elovirta at nokia dot com
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 16 Jul 2002 08:42:31 +0300
- Subject: RE: [xsl] conditional template matching & failure
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi,
> I tried doing something like:
>
> <xsl:template match="schedule[@username=$thisUser]">
Instead of trying to set the predicate in the match pattern (which you cant' do), select only the nodes you want to process (schedule[@username=$thisUser]) and write a template to match them (schedule).
> <table>
> <xs:apply-templates select="semester[season=$thisSeason and
> year=$thisYear]"/>
> </table>
> </xsl:template>
>
> <xsl:template match="semester[season=$thisSeason and year=$thisYear]">
Same applies here. You've already selected the nodes with the correct season and year in the apply-templates above, so here you can just make the template match semester elements.
> <xsl:for-each select="course">
> <tr><td><xsl:value-of select="title"/></td></tr>
> </xsl:for-each>
> </xsl:template>
So something like this:
<xsl:template match="schedules">
<xsl:choose>
<xsl:when test="schedule[@username = $thisUser]">
<xsl:apply-templates select="schedule[@username = $thisUser]" />
</xsl:when>
<xsl:otherwise>not found</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="schedule">
<table>
<xsl:apply-templates select="semester[season = $thisSeason and year = $thisYear]"/>
</table>
</xsl:template>
<xsl:template match="semester">
<xsl:for-each select="course">
<tr>
<td>
<xsl:value-of select="title"/>
</td>
</tr>
</xsl:for-each>
</xsl:template>
Cheers,
Jarno
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list