[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] two column table with alternating row colors using xsl xml and css


Subject: Re: [xsl] two column table with alternating row colors using xsl xml and css
From: Jarkko.Moilanen@xxxxxx
Date: Thu, 7 Aug 2003 13:19:47 +0300

Lainaus nicholse@xxxxxxxxxxxxxxxx:

Try (modulate) this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:myns="http://www.filemaker.com/fmpdsoresult">
<xsl:output method="html"/>
<!-- Root template of my stylesheet -->
  <xsl:template match="/">
     <html>
       <head>
          <title>Color rows</title>
        <style type="text/css">
        .r0 {background-color: white}
        .r1 {background-color: blue}
        </style>
       </head>
       <body>
        <table border="1">
          <xsl:apply-templates select="/myns:FMPDSORESULT/myns:ROW"/>
        </table>
      </body>
     </html>
   </xsl:template>

   <xsl:template match="myns:ROW">
     <tr class="r{position() mod 2}">
       <xsl:apply-templates/>
     </tr>
   </xsl:template>

</xsl:stylesheet>



<!-- XSL-List@xxxxxxxxxxxxxxxxxxxxxx
<!-- two column table with alternating row colors using xsl xml and css
<!-- I would like to create a balanced two column table with alternating row
<!-- colors sorted by business excluding html pre data for data non existant
<!-- in
<!-- the xml elements like () in the phone number. I am using the processor
<!-- php
<!-- extension http://nona.net/software/phplibxslt/:
<!-- 
<!-- <?
<!-- dl("php_libxslt.so");
<!-- $transformed = libxslt_transform($xmlstring, $xsltstring);
<!-- ?>
<!-- :
<!-- 
<!-- The data will come from xml:
<!-- <?xml version="1.0" encoding="UTF-8" ?>
<!-- <FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">
<!-- <ERRORCODE>0</ERRORCODE>
<!-- <DATABASE>Contacts-Master.fp5</DATABASE>
<!-- <LAYOUT></LAYOUT>
<!-- <ROW MODID="2" RECORDID="1">
<!-- <Co>Abbott Tinkers (Pat)</Co>
<!-- <Address1>736 Santa Anna Ave</Address1>
<!-- <City1>Miggs</City1>
<!-- <State1>CA</State1>
<!-- <Zip1>94430-9999</Zip1>
<!-- <Phone1_Area_Code>555</Phone1_Area_Code>
<!-- <Phone1_Number>121-7679</Phone1_Number>
<!-- </ROW>
<!-- <ROW MODID="2" RECORDID="2">
<!-- <Co>Aderbouy Specialty</Co>
<!-- <Address1>1557 Hemmy Drive</Address1>
<!-- <City1>Jesper</City1>
<!-- <State1>CA</State1>
<!-- <Zip1>99251</Zip1>
<!-- <Phone1_Area_Code></Phone1_Area_Code><! if phone number is missing
<!-- exclude
<!-- output of "(   )">
<!-- <Phone1_Number></Phone1_Number><! what if this tag is
<!-- "<Phone1_Number/>"?>
<!-- </ROW>
<!-- <! etcetera...>
<!-- </FMPDSORESULT>
<!-- :
<!-- 
<!-- I have tried a xsl like the following which works fine but dosent
<!-- implement two columns, sorting by business and alternating color rows.
<!-- I
<!-- am also not sure how fancy I can get with this processor. Every time I
<!-- try
<!-- to modify this xsl the processor returns raw xml to the browser. Tis is
<!-- the default behaviour if there are errors encountered:
<!-- <?xml version="1.0" encoding="UTF-8"?>
<!-- <xsl:stylesheet version="1.0"
<!-- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<!-- xmlns:fmp="http://www.filemaker.com/fmpdsoresult"
<!-- exclude-result-prefixes="fmp">
<!-- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<!-- <xsl:template match="fmp:FMPDSORESULT">
<!-- <HTML>
<!-- <HEAD>
<!-- <TITLE></TITLE>
<!-- </HEAD>
<!-- <BODY>
<!-- <TABLE>
<!-- <TR><TD><B>Contractors</B></TD><TD></TD></TR>
<!-- <xsl:for-each select="fmp:ROW">
<!-- <TR>
<!-- <TD>
<!-- <B><xsl:value-of select="fmp:Co" /></B><BR />
<!-- <xsl:value-of select="fmp:Address1" /><BR />
<!-- <xsl:value-of select="fmp:City1" />, <xsl:value-of select="fmp:State1"
<!-- />
<!-- <xsl:value-of select="fmp:Zip1" />
<!-- <BR />
<!-- </TD>
<!-- <TD>
<!-- (<xsl:value-of select="fmp:Phone1_Area_Code" />)<xsl:value-of
<!-- select="fmp:Phone1_Number" />
<!-- <BR />
<!-- </TD>
<!-- </TR>
<!-- </xsl:for-each>
<!-- </TABLE>
<!-- </BODY>
<!-- </HTML>
<!-- </xsl:template>
<!-- </xsl:stylesheet>
<!-- :
<!-- 
<!-- I read that using css with table or tr tags can cause browser
<!-- crashes/display problems at http://css.nu/examples/table-example.html .
<!-- Need I be worried?. I have not attempted an external css but maybe
<!-- something like this?:
<!-- 
<!-- tr.address_row {background-color: #FFFFFF;}
<!-- tr.address_row_alternate {background-color: #FFFFFF;}
<!-- 
<!-- I want the html/xhtml output to resemble this:
<!-- <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="2">
<!-- <TR VALIGN="top" CLASS="address_row" BGCOLOR="#FFFFFF">
<!-- <!altenating color would be EFEFEF>
<!-- <TD WIDTH="100%">
<!-- <B>
<!-- <!Co>company</B>
<!-- <BR>
<!-- <DIV CLASS="address">
<!-- <!address>address
<!-- <BR>
<!-- <!city>city, <!state>state <!zip>zip<BR>
<!-- </DIV>
<!-- </TD>
<!-- <TD VALIGN="bottom" nowrap>
<!-- <!phone>phone<BR>
<!-- </TD>
<!-- </TR>
<!-- </TABLE>
<!-- :
<!-- 
<!-- Is it safe/stable to impliment the templates from
<!-- http://xsltsl.sourceforge.net/ ? Would this provide functionality that
<!-- would help enable what I am trying to accomplish? I am struggling but
<!-- learning alot. Any advice or help is much appreciated!
<!-- Eric
<!-- 
<!--  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
<!-- 
<!-- 


***************************************************
* Jarkko Moilanen                                 *
* Project Researcher, ITCM (www.itcm.org)         *
* Profound XML technology Expert                  *
* University of Tampere                           *
* Hypermedia Laboratory                           *
***************************************************

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



Current Thread
Keywords