[xsl] Template Matching

Subject: [xsl] Template Matching
From: "Jeffrey Langdon" <jl_xsl@xxxxxxxxxxx>
Date: Thu, 27 Sep 2001 15:48:16 +0000
Hello All:

I have XML coming from a SQL database. The XSLT checks to see if the "IsActive" attribute in the z:row node is true. If it is, then a checkbox is ticked. I am having a little trouble understanding matching. What is the most efficent template match for the processor? I can't find a definitive answer on what the first template match should be compared to the second template. I am using template match="/" for the first and template match="rs:data" for the second. Is there a better way?

TIA,

Jeff Langdon

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
	xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
	xmlns:rs='urn:schemas-microsoft-com:rowset'
	xmlns:z='#RowsetSchema'>

<rs:data>
<z:row DayOfTheWeek='Sunday' IsActive='True' StartTime='08:00:00:000' EndTime='18:00:00:000'/>
<z:row DayOfTheWeek='Monday' IsActive='True' StartTime='08:00:00:000' EndTime='18:00:00:000'/>
<z:row DayOfTheWeek='Tuesday' IsActive='True' StartTime='08:00:00:000' EndTime='18:00:00:000'/>
<z:row DayOfTheWeek='Wednesday' IsActive='True' StartTime='08:00:00:000' EndTime='18:00:00:000'/>
<z:row DayOfTheWeek='Thursday' IsActive='True' StartTime='08:00:00:000' EndTime='18:00:00:000'/>
<z:row DayOfTheWeek='Friday' IsActive='True' StartTime='08:00:00:000' EndTime='18:00:00:000'/>
<z:row DayOfTheWeek='Saturday' IsActive='True' StartTime='08:00:00:000' EndTime='18:00:00:000'/>
</rs:data>
</xml>


<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform";
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:z="#RowsetSchema">

<xsl:template match="/">

	<table width="400" cellpadding="0" cellspacing="0" border="0">
	  <xsl:apply-templates  />
	 </table>
</xsl:template>


<xsl:template match="rs:data">
<tr>
<td width="100" >
<input type="checkbox" name="sunday" id="sunday">
<xsl:if test="z:row[@DayOfTheWeek='Sunday' and @IsActive='True']">
<xsl:attribute name="checked" />
<xsl:attribute name="onclick">scheduleDay_click('<xsl:value-of select="z:row/@DayOfTheWeek"/>')</xsl:attribute>
</xsl:if>
Sunday</input>
</td>
<td width="100" >
<input type="checkbox" name="monday" id="monday">
<xsl:if test="z:row[@DayOfTheWeek='Monday' and @IsActive='true']">
<xsl:attribute name="checked" />
<xsl:attribute name="onclick">scheduleDay_click('<xsl:value-of select="z:row/@DayOfTheWeek"/>')</xsl:attribute>
</xsl:if>
Monday</input>
</td>
<td width="100" >
<input type="checkbox" name="tuesday" id="tuesday">
<xsl:if test="z:row[@DayOfTheWeek='Tuesday' and @IsActive='true']">
<xsl:attribute name="checked" />
<xsl:attribute name="onclick">scheduleDay_click('<xsl:value-of select="z:row/@DayOfTheWeek"/>')</xsl:attribute>
</xsl:if>
Tuesday</input>
</td>
<td width="100" >
<input type="checkbox" name="wednesday" id="wednesday">
<xsl:if test="z:row[@DayOfTheWeek='Wednesday' and @IsActive='true']">
<xsl:attribute name="checked" />
<xsl:attribute name="onclick">scheduleDay_click('<xsl:value-of select="z:row/@DayOfTheWeek"/>')</xsl:attribute>
</xsl:if>
Wednesday</input>
</td>
</tr>
<tr>
<td width="100" >
<input type="checkbox" name="thursday" id="thursday">
<xsl:if test="z:row[@DayOfTheWeek='Thursday' and @IsActive='true']">
<xsl:attribute name="checked" />
<xsl:attribute name="onclick">scheduleDay_click('<xsl:value-of select="z:row/@DayOfTheWeek"/>')</xsl:attribute>
</xsl:if>
Thursday</input>
</td>
<td width="100" >
<input type="checkbox" name="friday" id="friday">
<xsl:if test="z:row[@DayOfTheWeek='Friday' and @IsActive='true']">
<xsl:attribute name="checked" />
<xsl:attribute name="onclick">scheduleDay_click('<xsl:value-of select="z:row/@DayOfTheWeek"/>')</xsl:attribute>
</xsl:if>
Friday</input>
</td>
<td width="100" >
<input type="checkbox" name="saturday" id="saturday">
<xsl:if test="z:row[@DayOfTheWeek='Saturday' and @IsActive='true']">
<xsl:attribute name="checked" />
<xsl:attribute name="onclick">scheduleDay_click('<xsl:value-of select="z:row/@DayOfTheWeek"/>')</xsl:attribute>
</xsl:if>
Saturday</input>
</td>
<td width="100" >
&#160;
</td>
</tr>
<tr>
<td colspan="4" >
&#160;
</td>
</tr>
<tr>
<td align="right" >Start Time</td>
<td>
<select name="start">
<option>
<xsl:value-of select="z:row/@StartTime"/>
</option>
<xsl:attribute name="onclick">scheduleTime_click('<xsl:value-of select="z:row/@StartTime"/>', '<xsl:value-of select="z:row/@EndTime"/>')</xsl:attribute>
</select>
</td>
<td align="right" >End Time</td>
<td>
<select name="end">
<option>
<xsl:value-of select="z:row/@EndTime"/>
</option>
<xsl:attribute name="onclick">scheduleTime_click('<xsl:value-of select="z:row/@StartTime"/>', '<xsl:value-of select="z:row/@EndTime"/>')</xsl:attribute>
</select>
</td>
</tr>


</xsl:template>
</xsl:stylesheet>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread