RE: RE: [xsl] alternate colors for table example - how does it work?

Subject: RE: RE: [xsl] alternate colors for table example - how does it work?
From: cknell@xxxxxxxxxx
Date: Tue, 17 Jun 2003 16:25:19 -0400
It's hard to say exactly what's wrong because your example XML document doesn't match the structure expected in the XSLT document. I suspect that you didn't post an accurate sample document, but how you can hope that we can help without accurate input is a mystery to me. We will need to know precisely what output you expect, an accurate input document, and if you want to fix a problem with a stylesheet, an accurate copy of your XSLT document.

Here are a few problems with the XML document you posted:
 Your XSLT expects to output the values of these elements when there are no such elements in this document:
 o buysell
 o counterparty
 o funds/fundpar
 o funds/fundname
 o funds/fundfacility/name
 o funds/fundfacility/amount
 o funds/fundfacility/price

 This XML document is not well-formed, there is a "trade" opening tag with no corresponding closing tag just before the stylesheet closing tag.

On examining your stylesheet, it appears that you expect to perform the transformation in the browser rather than on the server using a stand-alone transformer. There's no problem with that, but saying so explicitly in your question would have simplified analysis of your problem.

I have been following this list for some time and you are not the first, nor certainly will you be the last, person to post a question without enough information to make solving the problem easy. The purpose of pointing out these problems is to encourage you (and others) to spend more time formulating your questions clearly, and to supply all the information we might need to help. That being said, I have worked up an XML document which matches your XSLT document. Please look this over and confirm that this is the structure of the XML that your XSLT document is expecting, or correct it as necessary. When I am certain of the structure of the XML, I'll complete my XSLT to output what I think you want and we can proceed from there.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<trades>
 <trade>
  <par></par>
  <buysell></buysell>
  <counterparty></counterparty>
  <borrower></borrower>
  <method></method>
  <tradedate></tradedate>
  <tradeclosedate></tradeclosedate>
  <facilities>
    <name></name>
    <amout></amout>
    <price></price>
    <currency></currency>
  </facilities>
  <repdocuments>
    <docpath></docpath>
    <docdescrip></docdescrip>
  </repdocuments>
  <funds>
    <fundpar></fundpar>
    <fundname></fundname>
    <fundfacilities>
      <name></name>
      <amount></amount>
      <price></price>
      <currency></currency>
    </fundfacilities>
  </funds>
 </trade>
</trades>

-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     "dmitrik@xxxxxxxxxxxxxx" <dmitrik@xxxxxxxxxxxxxx>
Sent:     Tue, 17 Jun 2003 15:04:42 -0400
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  RE: [xsl] alternate colors for table example - how does it work?

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<?xml-stylesheet type="text/xsl" href="borrowerD.xsl"?>
<trades>
<trade>
<par>8335</par>
<buyer>test</buyer>
<seller>test</seller>
<agent>test</agent>
<borrower>test.</borrower>
<tradedate>04/09/2003</tradedate>
<tradeclosedate>05/01/2003</tradeclosedate>
<facilities>
<name>Loans</name>
<amount>1e+007</amount>
<price>98.5</price>
</facilities>
<repdocuments>
<docdescrip>Confirmation</docdescrip>
<docpath>r:\8335\8335Confirm.snp</docpath>
</repdocuments>
<repdocuments>
<docdescrip>Confirmation Buyer Attachment</docdescrip>
<docpath>r:\8335\Burns HVB confirm.tif</docpath>
</repdocuments>
<repdocuments>
<docdescrip>Assignment And Acceptance</docdescrip>
<docpath>r:\8335\8335AnA.snp</docpath>
</repdocuments>
<repdocuments>
<docdescrip>Assignment Buyer Attachment</docdescrip>
<docpath>r:\8335\HVB aAnda.tif</docpath>
</repdocuments>
<repdocuments>
<docdescrip>Funding Memo</docdescrip>
<docpath>r:\8335\8335FundingMemo.snp</docpath>
</repdocuments>
<repdocuments>
<docdescrip>Purchase Price Letter</docdescrip>
<docpath>r:\8335\8335FundingMemoPPL.snp</docpath>
</repdocuments>
</trade>
<trade>
<trades>



Original Message:
-----------------
From:  cknell@xxxxxxxxxx
Date: Tue, 17 Jun 2003 14:43:43 -0400
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] alternate colors for table example - how does it work?


What does your XML data document look like?
-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     "dmitrik@xxxxxxxxxxxxxx" <dmitrik@xxxxxxxxxxxxxx>
Sent:     Tue, 17 Jun 2003 13:35:37 -0400
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  [xsl] alternate colors for table example - how does it work?

how can this example work with my code (bottom of page)?

where does this code:

 <xsl:template match="ROW">
      <tr class="r{position() mod 2}">
        <xsl:apply-templates/>
      </tr>
    </xsl:template>
 fit with my code at the bottom of the page?
I tried a few things, but nothing seems to work.
My <style> in the page is only called, when directly in the
page, not when using link.

how is this 

# My CSS File named "Something.css"
    .r0 {background-color: #f9f9f9}
    .r1 {background-color: #f7f7e7}


supposed to be called?

tia,
dk

----EXAMPLE ----------------------------------

 Alternate colors on TABLE rows
 
 Steve Muench

| Does anyone have any tips for adding a background color to every
*alternate*
| TABLE row in the result tree?

There are lots of ways to do this, but the one I've settled on in the
XSLT-driven database apps I build is the following: 

(1) I create a CSS Stylesheet containing two CSS classes like "row0" and
"row1" as follows (I shorten to "r0" and "r1"):

    # My CSS File named "Something.css"
    .r0 {background-color: #f9f9f9}
    .r1 {background-color: #f7f7e7}

(2) I create an XSLT stylesheet that creates an HTML page that links to
this Something.css stylesheet:

<!-- Root template of my stylesheet -->
    <xsl:template match="/">
      <html>
        <head>
           <title>Cool XSLT App</title>
           <link rel="stylesheet" type="text/css" href="Something.css"/>
        </head>
        <body><xsl:apply-templates/></body>
      </html>
    </xsl:template>

(3) In my template that is creating HTML table rows, I use an attribute
value template to alternate the *name* of the CSS class in use for that row
to "toggle" between the names "r0" for even rows and "r1" for odd rows...

    <!-- Match a row of database query query results in XML -->
    <xsl:template match="ROW">
      <tr class="r{position() mod 2}">
        <xsl:apply-templates/>
      </tr>
    </xsl:template>

The expression {position() mod 2} will alternate between the values 1 and 0
so the effective value of the "class" attribute on the <tr> element I'm
creating is "r1" and "r0".

This way, I can control the fonts/colors of my entire site by touching a
single CSS file, while XSLT takes care of all the fancy stuff.
 
====================================END OF EXAMPLE
my code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


 <xsl:template match="/">
      <html>
        
      
 <style>
   td { width: 250px } 
   
    	
   </style>

<?xml-stylesheet href="something.css" type="text/css"?>
        
        <body>
   

   <!--<?xml-stylesheet href="something.css" type="text/css"?>-->


   
    <table border="1">
     <tr>
      <td>Trade #</td>
      <td>Buy/Sell</td>
      <td>Counterparty</td>
      <td>Borrower</td>
      <td>Method</td>
      <td>Trade Date</td>
      <td>Trade Close Date</td>
      <td>Facilities (Name,Amount,Price,Currency)</td> 
      <td width="10%">Trade Documents                     </td>     
      <td>Funds (Trade#, Name,Facilities (Name,Amount,Price,Currency),
Documents)</td>                      
     </tr>    
     <xsl:for-each select="trades/trade">
       <xsl:sort select="trade" order="ascending"/>	
      <tr class="r{position() mod 2}">
       <td> 
         <xsl:value-of select="par"/>
       </td>
       <td>
        <xsl:value-of select="buysell"/>
       </td>
       <td>
        <xsl:value-of select="counterparty"/>
       </td>
       <td>
        <xsl:value-of select="borrower"/>
       </td>
       <td>
        <xsl:value-of select="method"/>
       </td>
       <td>
        <xsl:value-of select="tradedate"/>
       </td>
       <td>
        <xsl:value-of select="tradeclosedate"/>
       </td>
       <td>
        <xsl:for-each select="facilities">
         <table border="1">
          <tr>
           <td>
            <xsl:value-of select="name"/>
           </td>
           <td>
            <xsl:value-of select="amount"/>
           </td>
           <td>
            <xsl:value-of select="price"/>
           </td>
	   <td>
            <xsl:value-of select="currency"/>
           </td>
          </tr>
         </table>
        </xsl:for-each>
       </td>
       <td>
        <xsl:for-each select="repdocuments">
         <table >
          <tr>           
           <td>               
            <a href="{docpath}" target="_blank">	<xsl:value-of
select="docdescrip"/> </a>	
           </td>           
          </tr>
         </table>
        </xsl:for-each>
       </td>  	  
       <td>
        <xsl:for-each select="funds">	 
         <table border="1">
          <tr>           
	 
           <td>               
             <xsl:value-of select="fundpar"/>
           </td>  
           <td>               
             <xsl:value-of select="fundname"/>
           </td>  
	   <td>
            <xsl:for-each select="fundfacilities">
             <table border="1">
              <tr>
               <td>
                <xsl:value-of select="name"/>
               	 </td>
                  <td>
                   <xsl:value-of select="amount"/>
                    </td>
                     <td>
                   <xsl:value-of select="price"/>
                  </td>
	        <td>
              <xsl:value-of select="currency"/>
             </td>
           </tr>
         </table>
        </xsl:for-each>
       </td>
           <td>
			 <xsl:for-each select="funddocuments">
			  <table border="1">
			   <tr>           
			    <td>               
			     <a href="{docpath}" target="_blank">	<xsl:value-of
select="docdescrip"/> </a>	
			    </td>           
			   </tr>
			  </table>
			 </xsl:for-each>
			</td>                            
          </tr>
         </table>
        </xsl:for-each>
       </td>           
      </tr>
     </xsl:for-each>     

    </table>
   <xsl:apply-templates/>
   </body>
  </html>
 
 </xsl:template>
</xsl:stylesheet>



--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .



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




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


--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .



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




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


Current Thread