[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|