[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: variable change in xsl:for-each
Markus: The issue may occur where you might want to skip a row based upon another criteria rather than the fact that you current position is odd or even.... e.g. <rows> <item position="1" visible="1">value</item> <item position="2" visible="0">value</item> <item position="3" visible="1">value</item> <item position="4" visible="1">value</item> <item position="5" visible="1">value</item> <item position="6" visible="0">value</item> </rows> if you then used position in the document to indicate what color a row would be then the code below would not work as desired... so the solution is to call a function to set your variable e.g. <msxml:script> var CurrentColorValue = 'red'; function ChangeColor() { if (CurrentColorValue == 'red') { CurrentColorValue = 'blue'; return('blue'); } else { CurrentColorValue = 'red'; return('red'); } } </msxml:script> =============== <table> <xsl:for-each select="item"> <xsl:variable name="RowColor" select="scriptUser:ChangeColor"/> <tr><td bgcolor="{$RowColor}" ><xsl:value-of select="."></td></tr> </xsl:for-each> </table> =============== this method will then toggle the color only when you actually want it to rather than depend upon the position of the item in document order. ================================================================= ================================================================= |-----Original Message----- |From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx |[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Jason Macki |Sent: Monday, July 22, 2002 11:27 AM |To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx |Subject: RE: variable change in xsl:for-each | | |Hi Markus, | |You can't update the content of a variable with XSLT. | |In order to alternate the colour of your cell, use the position() and |mod() functions to determine if the current position is odd or even. | |For example, this XML: | |<rows> | <item>one</item> | <item>two</item> | <item>three</item> |</rows> | |...used against this XSLT: | |<xsl:for-each select="rows/item"> | <xsl:choose> | <xsl:when test="(position() mod 2) = 0">Even</xsl:when> | <xsl:otherwise>Odd</xsl:otherwise> | </xsl:choose> | <br /> |</xsl:for-each> | |..will produce the following result: | |Odd |Even |Odd | |If you haven't heard of mod() before, a mod b returns the number of |times b can be subtracted from a without returning a negative result. | |- Jason | |-----Original Message----- |From: inchi2000@xxxxxx [mailto:inchi2000@xxxxxx] |Sent: Monday, July 22, 2002 11:06 AM |To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx |Subject: variable change in xsl:for-each | | |Hello, | |I want the background to change in each cell. But in every cell I only |get the #FFFFFF-background. I think the variable isn't updated in the |choose-procedure. But I don't know why. Hope you can help. | |Thanks! |Markus | |Sorry!!! I forget the subject in last mail. So I posted again | |heres my xsl-file: | |<xsl:variable name="xrowcolor" select="false()"/> |<xsl:variable name="rowcolor">#FFFFFF</xsl:variable> |<xsl:for-each select="//meldungen"> | <xsl:choose> | <xsl:when test="$xrowcolor"> | <xsl:variable name="rowcolor">#FFFFFF</xsl:variable> | <xsl:variable name="xrowcolor" select="false()"/> | </xsl:when> | <xsl:otherwise> | <xsl:variable name="rowcolor">#FFFF11</xsl:variable> | <xsl:variable name="xrowcolor" select="true()"/> | </xsl:otherwise> | </xsl:choose> | <fo:table-cell> | <fo:block background-color="{$rowcolor}" font-weight="bold"> | <xsl:value-of select="eingang"/> | </fo:block> | </fo:table-cell> |</fo:for-each> | |-- |GMX - Die Kommunikationsplattform im Internet. http://www.gmx.net | | | XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list | | | XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list | | XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|