RE: [xsl] Elminitate redundancy by using variables

Subject: RE: [xsl] Elminitate redundancy by using variables
From: Pieter Reint Siegers Kort <pieter.siegers@xxxxxxxxxxx>
Date: Wed, 24 Mar 2004 10:39:53 -0600
Yes, but as Michael mentioned you do not have to use variables nor params,
and that's what your question was about... So you got me a bit confused.
Anyway, my reply was floating around as I was not getting the usual list
server output, this seems to have been corrected now.

<prs/> 

-----Original Message-----
From: Kenny Akridge [mailto:kenny@xxxxxxxxxxxxxxxxx] 
Sent: Wednesday, March 24, 2004 8:40 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Elminitate redundancy by using variables

Funny you mention that because I actually am already doing that :)


-----Original Message-----
From: Pieter Reint Siegers Kort [mailto:pieter.siegers@xxxxxxxxxxx]
Sent: Wednesday, March 24, 2004 9:33 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Elminitate redundancy by using variables

Hi Kenny,

>Is there a way to save the value from the beginning of the <td> to the 
>end,

>including the generate value of LineItemName?

You may be able to just use xsl:param or xsl:variable within your template,
and to avoid the repeating you mention you should iterate through the td
elements by simply defining a template at that node level, and the XSL
processor will automatically loop through them. One way to do this is to use
xsl:apply-templates which selects the node-set to process, in this case the
nodes you want to process in your TD elements. 

An example that does this and uses an alternating row color value is as
follows (note that it does not use params nor variables):

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl local xql"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:local="#local-functions"
xmlns:xql="#xql-functions">

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="/">
	<html>
	<head>
	<title>ASP 3.0 (classic) to ASP.NET C# Performance Tests</title>
	</head>
	<body bgcolor="#efc6ff">
		<h3 align="center" style="width:600">ASP 3.0 (classic) to
ASP.NET C# Performance Tests</h3>
		<table border="1">
		<tr><td>
		<table cellpadding="3" cellspacing="0" border="0"
width="600">
			<tr>
				<th align="left" bgcolor="Lightblue"><font
color="white">Customer ID</font></th>
				<th align="left" bgcolor="Lightblue"><font
color="white">Company Name</font></th>
				<th align="left" bgcolor="Lightblue"><font
color="white">Contact Name</font></th>
			</tr>
			<xsl:apply-templates select="root/Customers"/>
		</table>
		</td></tr>
		</table>
	</body>
	</html>
</xsl:template>

<xsl:template match="Customers">
   <tr>
	<xsl:attribute name="bgcolor">
        <xsl:choose>
          <xsl:when test="position() mod 2 = 0">#ccfec7</xsl:when>
          <xsl:otherwise>#feffc6</xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
	<td>
		<xsl:value-of select="CustomerID"/>
	</td>
	<td>
		<xsl:value-of select="CompanyName"/>
	</td>
	<td>
		<xsl:value-of select="Country"/>
	</td>
   </tr>
</xsl:template>

</xsl:stylesheet>

HTH, Pieter 

Current Thread