This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: conditional template matching & failure


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]