Subject: RE: Something similar to managing behavior with a variable
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 5 Apr 2005 19:36:02 +0100
|
Here are some of the design patterns you might consider:
(a) computing the column number based on the counting selected nodes in the
source tree (using count() or xsl:number)
(b) computing the number based on the position of the node in the current
node list (the position() function)
(c) "iterating" over the nodes by head-tail recursion, maintaining a counter
as you do so (by passing a parameter on the recursive call)
(d) a two-phase transformation in which you generate the output nodes as a
plain sequence in the first pass and then number them or group them (or
colour them) in a second pass.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Luke Shannon [mailto:lshannon@xxxxxxxxxxxxxxx]
> Sent: 05 April 2005 18:57
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Something similar to managing behavior with a variable
>
> Hello;
>
> I'm creating a UI that writes rows of data. The background of
> the row needs
> to changes every second row. I was doing it like this:
>
> <tr align="left" valign="middle" class="grey1ColumnText">
> <xsl:choose>
> <xsl:when test='number($position) mod 2 != 0'>
> <xsl:attribute name="class">grey1ColumnText</xsl:attribute>
> </xsl:when>
> <xsl:otherwise>
> <xsl:attribute name="class">grey2ColumnText</xsl:attribute>
> </xsl:otherwise>
> </xsl:choose>
> </tr>
>
> My problem now is now have a condition that determines when a
> row is to be
> written. So, in a collection of 5 items maybe only 1 and 4
> get written. I
> still need a way to figure out how to alternate the
> background for the rows
> that actually get written. Position no longer does the trick.
>
> I thought I could keep the previous background in a variable
> like below:
>
> <tr align="left" valign="middle" class="grey1ColumnText">
> <xsl:choose>
> <xsl:when test="$resultBK = 'grey1ColumnText'">
> <xsl:attribute name="class">grey2ColumnText</xsl:attribute>
> <xsl:variable name="resultBK" select="string('grey2ColumnText')"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:attribute name="class">grey1ColumnText</xsl:attribute>
> <xsl:variable name="resultBK" select="string('grey1ColumnText')"/>
> </xsl:otherwise>
> </xsl:choose>
> </tr>
>
> But I have just found out you can't change the contents of a
> global variable
> (resultBK) after it has been defined. How can I handle this?
>
> Thanks,
>
> Luke
>
> Luke Shannon | Software Developer
> FutureBrand Toronto
>
> 207 Queen's Quay, Suite 400
> Toronto, ON, M5J 1A7
> 416 642 7935 (office)
|