[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: Alternate bg colors for table and address summaries
Subject: Re: Alternate bg colors for table and address summaries From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Thu, 26 Oct 2000 10:05:01 +0100 |
Robert, >I want to have one summary return with a grey background and the other >summary with a white background. One thing before looking at the solution to your problem. In your XSLT stylesheet, you have: ><HTML xmlns:xsl="http://www.w3.org/TR/WD-xsl"> This is the old namespace for XSLT, which is now "http://www.w3.org/1999/XSL/Transform". You should change your HTML start tag to be: <HTML xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"> You should also make sure that you have the latest version of MSXML (September) so that you can use conformant XSLT in all its glory. You can get it from http://msdn.microsoft.com/downloads/webtechnology/xml/msxml.asp and should also take a look at the unofficial MSXML FAQ at http://www.netcrucible.com/xslt/msxml-faq.html. So... on to your problem. You want to have the two summaries in different colours. The place where you set the colour of the summary is within @STYLE attribute of the DIV element: > <DIV STYLE="background-color:#FFFFFF; color:white; padding:4px"> Now, for the first summary, you want a gray background: STYLE="background-color:gray; color:white; padding:4px" And for the second summary, you want a white background: STYLE="background-color:white; color:white; padding:4px" To change the value of an attribute dependent on a condition, the best thing to do is to use xsl:attribute to create the attribute, and then xsl:choose to determine what the content should be inside it: <DIV> <xsl:attribute name="STYLE"> <xsl:choose> <xsl:when test="...">background-color:gray; </xsl:when> <xsl:otherwise>background-color:white; </xsl:otherwise> </xsl:choose> <xsl:text>color:white; padding:4px</xsl:text> </xsl:attribute> ... </DIV> The difficulty that it sounds like you were facing is what the 'test' should be - how to determine whether the background colour should be gray or white. At the point at which this test is made, you're within an xsl:for-each; the current node is a Summary, and the current node list contains all the Summary elements that are children of Address-Summaries within the document. This means you can tell whether the current node (a Summary) is the first Summary element in the list or not by checking its position(): test="position() = 1" If you have lots of Summary elements and you want to alternate colours odd and even, then you can check whether a Summary element is in an odd position using mod: test="position() mod 2 = 1" So, try: <DIV> <xsl:attribute name="STYLE"> <xsl:choose> <xsl:when test="position() mod 2 = 1">background-color:gray; </xsl:when> <xsl:otherwise>background-color:white; </xsl:otherwise> </xsl:choose> <xsl:text>color:white; padding:4px</xsl:text> </xsl:attribute> ... </DIV> I hope that this helps, Jeni Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Alternate bg colors for table and a, Robert Saylor | Thread | .. and parent::node(), Alex Albu |
RE: How to &&, Kay Michael | Date | RE: .. and parent::node(), Kay Michael |
Month |
Keywords