xsl-list
[Top] [All Lists]

Re: xsl:variable with hex color values

2005-05-22 08:59:50
Michael Kay wrote:

Another solution to add to the list you've been given: In XSLT 2.0 you can
do

<td bgcolor="{if (position() mod 2) then 'black' else 'white'}">
 ...
</td>

If you want to be terse and don't mind being obscure, you can write things
in XSLT 1.0 like

<td bgcolor="#{substring('FFFFFF000000', (position() mod 2 * 6) + 1, 6)}">
 ...
</td>

Michael Kay


I've tried the solution you've mentioned and got "Error loading stylesheet: Parsing an XPath expression failed".
Here's the XML and XSL documents I've used:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="teste.xsl"?>

<tests>
   <test>
       1
   </test>
   <test>
       2
   </test>
   <test>
       3
   </test>
   <test>
       4
   </test>
</tests>


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:fo="http://www.w3.org/1999/XSL/Format"; xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns:fn="http://www.w3.org/2004/07/xpath-functions"; xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes";> <xsl:output method="html" indent="yes"/> <xsl:template match="/">
       <html>
           <head/>

           <body>
               <table>

                   <xsl:for-each select="//test">
                       <tr>
<td bgcolor="{if (position() mod 2) then 'black' else 'white'}">
                               <xsl:value-of select="."/>
                               <br/>
                           </td>
                       </tr>

                   </xsl:for-each>

               </table>

           </body>
       </html>

   </xsl:template>
</xsl:stylesheet>

Is something wrong with this example? How can I solve the problem?

Thank you for your assistance, regards, Rolando

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--