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

RE: conditional template matching & failure

Subject: RE: conditional template matching & failure
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 16 Jul 2002 08:42:31 +0300
conditional templates xsl
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


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.