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]

RE: XSLT Problem


Alex, 
First of all, someone is going to tell you not to use <for-each>. The rule
has always been "Beginners never use <for-each>". The reason is that what
you want to do is better served (and better XSL) with apply templates. You
are also doing your test in the wrong location...


Try this:
<xsl:stylesheet>
<xsl:template match="/" >
...
<xsl:apply-templates select="Record01[field-C = '  '">
	<xsl:sort select="field-A" />
	<xsl:sort select="field-B" />
</xsl:apply-templates>
...
</xsl:template>

<xsl:template match="Record01">
	<xsl:variable name="ClassName">
		<xsl:choose>
			<xsl:when test="position() mod 2 = 0">C1</xsl:when>
			<xsl:otherwise>C2</xsl:otherwise>
	</xsl:variable>
<TR>
<TD class="{$ClassName}"><xsl:value-of  select="field-A"/></td>
<TD class="{$ClassName}"><xsl:value-of  select="field-B"/></td>
<TD class="{$ClassName}"><xsl:value-of  select="field-C"/></td>
</tr>
</xsl:template>

> -----Original Message-----
> From: Alex Genis [mailto:agenis@dtcc.com]
> Sent: Wednesday, June 20, 2001 12:12 PM
> To: XSL-List@lists.mulberrytech.com
> Subject: [xsl] XSLT Problem
> 
> 
> Hi ! Could you please help ?
> My task is : to create HTML report from XML document and to 
> color every other
> row  for the result HTML table.
> Everything is already done but I still have one problem:
> 
> If I use
> 
>   <xsl:for-each select="Record01">
>    <xsl:sort select="field-A"/>
>    <xsl:sort select="field-B"/>
> 
>      <xsl:if test="field-C = '  '" >
>         <TR>
>           <xsl:choose>
>            <xsl:when test="position() mod 2 = 0">
>              <TD   ...   class="C1">
>                                        <xsl:value-of 
> select="field-A"/>
>              </TD>
>              <TD   ...   class="C1">
>                                        <xsl:value-of 
> select="field-B"/>
>              </TD>
>              <TD   ...   class="C1">
>                                        <xsl:value-of 
> select="field-C"/>
>              </TD>
>            </xsl:when>
>            <xsl:otherwise>
>              <TD   ...   class="C2">
>                                        <xsl:value-of 
> select="field-A"/>
>              </TD>
>              <TD   ...   class="C2">
>                                        <xsl:value-of 
> select="field-B"/>
>              </TD>
>              <TD   ...   class="C2">
>                                        <xsl:value-of 
> select="field-C"/>
>              </TD>
>            </xsl:otherwise>
>         </xsl:choose>
>       </TR>
>    </xsl:if>
> 
> </xsl:for-each>
> 
> I've got result table where I can not color every other row 
> because as I
> understand the system :
> 1. retrieves rows and sorts them by appropriate keys;
>    for example :
>      1-st row   (value of C-field is '  ') - black;
>      2-nd row (value of C-field is '11') - gray;
>      3-rd row  (value of C-field is '  ') - black;
>      4-th row   (value of C-field is '22') - gray;
>      5-th row   (value of C-field is '  ') - black;
>      6-th row   (value of C-field is '  ') - gray;
> 
> 2. and only then excludes 2-nd and 4-th rows( where field-C 
> not = '  ')
> 
> So instead of sequence :
> 
> 1-st row (value of C-field is '  ') - black;
> 3-rd row (value of C-field is '  ') - gray;
> 5-th row (value of C-field is '  ') - black;
> 6-th row (value of C-field is '  ') - gray
> 
> I've got :
> 
> 1-st row (value of C-field is '  ') - black;
> 3-rd row (value of C-field is '  ') - black;
> 5-th row (value of C-field is '  ') - black;
> 6-th row (value of C-field is '  ') - gray
> 
> Or other words does XSLT give us the posibility to use 
> something like "where" in
>  DB2 ?
> And if it does - how to use it within <xsl:for-each> or 
> <xsl:apply-templates
> select="..."> BEFORE SORTING ?
> 
> How this problem can be solved ?
> Thanks a lot. Alex Genis.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  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]