RE: [xsl] Table alternate rows colors within xsl:sort

Subject: RE: [xsl] Table alternate rows colors within xsl:sort
From: Michael Tihon <michaeltihon@xxxxxxxxx>
Date: Thu, 20 Nov 2003 03:57:41 -0800 (PST)
Thanx Andrew. I found another solution to solve my problem. Another member told me that position()
was in fact the position after the sort, what is true. My only error was not to sort correcly :)

now I do the restriction on the type in the for-each:

<xsl:template name="list">                              
<xsl:param name="type"/>                                
<table class="table" cellpadding="2" cellspacing="1" wid
	<xsl:for-each select="links/link[@type = $type]">   
		<xsl:sort order="ascending" select="name"/>     
			<xsl:choose>                                
				<xsl:when test="position() mod 2 = 0">  
					<tr>                                
						<td class="tablerow1"><a href="{...
						<td class="tablerow1"><xsl:value...
					</tr>                               
				</xsl:when>                             
				<xsl:otherwise>                         
					<tr>                                
						<td class="tablerow2"><a href="{...
						<td class="tablerow2"><xsl:value...
					</tr>                               
				</xsl:otherwise>                        
			</xsl:choose>                               
	</xsl:for-each>                                     
</table>                                                
</xsl:template>                                         

But I thank you for your idea because it is really very interesting... I didn't imagine that was
possible to do such builds in a variable.

Now, I ask you : What is at your opinion the difference between the use of a variable and a call
template ?




--- Andrew Welch <AWelch@xxxxxxxxxxxxxxx> wrote:
> 
> 
> > I would want to display a datagrid which lines colors
> > varies regarding the position (one line white, one
> > line gray, one line white, ...) AFTER an xsl:sort.
> > 
> > The problem is that the "<xsl:if test="position() mod
> > 2 = 0"> won't work after a <xsl:sort> because the
> > position() function returns the position in the
> > original xml, not the in sorted nodes.
> > 
> > I can't use a variable because xslt do not allow to
> > increment it within my xsl:for-each
> > 
> > Do someone know a solution to this ?
> 
> A simple way is to do the sort in a variable first, then for-each over
> the variable to produce your table rows.
> 
> <xsl:variable name="sortedRows-rtf">
>   <xsl:for-each select="links/link">
>     sort, xsl:copy etc...
>   </xsl:for-each>
> </xsl:variable>
> <xsl:variable name="sortedRows" select="xxx:node-set($sortedRows-rtf)"/>
> 
> Then...
> 
> <table>
>   <xsl:for-each select="$sortedRows">
>     <xsl:for-each select="link">
>        ....
> 
> 
> Get the idea?
> 
> Whenver you have some multi-stage processing to do, just split it up
> into variables, each one working on the previous one.
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread