This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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@lists.mulberrytech.com
|[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Jason Macki
|Sent: Monday, July 22, 2002 11:27 AM
|To: xsl-list@lists.mulberrytech.com
|Subject: RE: [xsl] 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@gmx.de [mailto:inchi2000@gmx.de] 
|Sent: Monday, July 22, 2002 11:06 AM
|To: XSL-List@lists.mulberrytech.com
|Subject: [xsl] 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]