[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: Américo Albuquerque <melinor@xxxxxxx>
Date: Thu, 07 Aug 2003 16:22:43 +0100 (WEST)

Hi.

Citando nicholse@xxxxxxxxxxxxxxxx:

(...)
} Also, maybe hard to understand/explain. I want two colums. In both columns
} are companies starting col 1 top left to bottom right col 2 listed in
} alpebetical order. I do not understand why this would not work. Processor
} complains about me trying to put the </tr><tr> between two <td>'s of an
} even and odd.
} 

You can not do that, xslt is xml and has to be well-formed
so you can not have a </tr><tr> inside a <xsl:if></xsl:if>, that is not a well-formed 
xml.

(...)
} <xsl:template match="fmp:ROW">
This template is matching fmp:ROW nodes

} <xsl:for-each select="fmp:ROW">
This for-each is mathing fmp:ROW that are direct childs of the above

for this to work you data should be
<fmp:ROW>
  <fmp:ROW>
    ...
  </fmp:ROW>
  ...
</fmp:ROW>

and it insn't. so this for-each will do nothing at all

I've changed the templates I've send you to do this. you'll need to add 
xmlns:fn="http://exslt.org/common" if you're using saxon or xalan or add 
xmlns:fn="urn:schemas-microsoft-com:xslt" for msxml

Regards,
Americo Albuquerque

New Templates:
  <xsl:template match="fmp:FMPDSORESULT">
    <!-- you need to set this variable so you can pass a sorted nodeset -->
    <xsl:variable name="rows">
      <xsl:for-each select="fmp:ROW">
        <xsl:sort select="fmp:Co"/>
        <xsl:copy-of select="."/>
      </xsl:for-each>
    </xsl:variable>
    <html>
      <head>
        <title/>
        <style>
          .r0 { background-color: silver; color: black; } 
          .r1 { color: gray; } 
        </style>
      </head>
      <body>
        <table>
          <tr>
            <td>
              <b>Contractors</b>
            </td>
            <td>&#160;</td>
          </tr>
          <!-- select only the nodes that start each row -->
          <xsl:apply-templates select="fn:node-set($rows)/fmp:ROW[position() mod 2=1]"/>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="fmp:ROW">
    <!-- use following-sibling::fmp:ROW[1] to get the next sibling for the same row -->
    <tr class="r{position() mod 2}">
      <td class="r{position() mod 2}">
        <xsl:value-of select="fmp:Co"/>
      </td>
      <td class="r{position() mod 2}">
        <xsl:value-of select="following-sibling::fmp:ROW[1]/fmp:Co"/>
      </td>
    </tr>
  </xsl:template>

___________________________________________________________________

O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt


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



Current Thread
Keywords