[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problem With Different Colors for Alternate Rows

Subject: RE: Problem With Different Colors for Alternate Rows
From: "Schwartz, Rechell R, ALCAS" <rrschwartz@xxxxxxx>
Date: Tue, 5 Nov 2002 16:43:29 -0500
oddrowstyle
Jeorg,

Thank you. Mode seems to be working ok, except for one thing -- in my
real XSLT (which is more complicated than the sample below), for certain
data elements (e.g., side dish) I search for multiple occurences of the
element and I concatenate them with commas as below. This is causing
confusion in the assessment of the position() function. It seems to
think I am looking for the position of the row, when I am really looking
for the position of this particular side dish. This confusion is causing
each side dish to print out on a new line instead of on a single line
with a comma-separated list. Is there any way to test if this side dish
is first or last w/o using the position() function (thus avoiding this
type of confusion)?

<xsl:template match="Side_Dish">
<xsl:if test="position() = 1">
	<xsl:text disable-output-escaping="yes">&lt;td
class="oddRowStyle"&gt;Side Dish:&lt;td
class="oddRowStyle"&gt;</xsl:text>
</xsl:if>
      <xsl:value-of select="."/>
<xsl:choose>
	<xsl:when test="position() != last()">
 		<xsl:text>, </xsl:text>
	</xsl:when>
	<xsl:otherwise>
		<xsl:text
disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
	</xsl:otherwise>
</xsl:choose>
</xsl:template>

Thanks,
Rechell Schwartz

-----Original Message-----
From: Joerg Heinicke [mailto:joerg.heinicke@xxxxxx]
Sent: Tuesday, November 05, 2002 1:11 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Problem With Different Colors for Alternate Rows


Hello Rechell,

there is also a simple XSL way:

<xsl:template match="/Food_List">
   <table>
     <xsl:apply-templates select="Main_Food_List | Side_Dish | Desert" 
mode="row"/>
   </table>
</xsl:template>

<xsl:template match="*" mode="row">
   <TR class="evenRowStyle">
     <xsl:if test="position() mod 2 = 1">
       <xsl:attribute name="class">oddRowStyle</xsl:attribute>
     </xsl:if>
     <xsl:apply-templates select="."/>
   </TR>
</xsl:template>

<xsl:template match="Main_Food_List">
   <TD>Main Course:</TD>
   <TD><xsl:value-of select="Main_Course"/></TD>
</xsl:template>

<xsl:template match="Side_Dish">
   <TD>Side Dish:</TD>
   <TD><xsl:value-of select="."/></TD>
</xsl:template>

<xsl:template match="Desert">
   <TD>Desert:</TD>
   <TD><xsl:value-of select="Fancy_Desert"/></TD>
</xsl:template>

Regards,

Joerg

Schwartz, Rechell R, ALCAS wrote:
> All,
> 
> I am having difficulty programming a stylesheet that is supposed to
return the result set as a list of HTML rows in alternating colors.All
of the examples that I have seen address how to do this if every data
row is is derived from the same type of XML tag. But in my example, each
row may come from a completely different section of the XML. Following
is a sample XML similar to the one that I am using. Also, another
constraint is if any row is missing, it is inhibited, and the
alternating color rule must still be preserved. I have tried numerous
ways of passing parameters, but have been unable to modify the the row
count after a match was found ofr each item. Any help would be GREATLY
appreciated.
> 
> Sample XML:
> 
> <Food_List>
> <Main_Food_List>
> <Main_Course>
> Chicken
> </Main_Course>
> </Main_Food_List>
> <Side_Dish>
> Potatoes
> </Side_Dish>
> <Desert>
> <Fancy_Desert>
> Chocolate Truffles
> </Fancy_Desert>
> </Desert>
> </Food_List>
> 
> Sample XSLT Stylesheet:
> <?xml version="1.0" ?>
> <xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
> <xsl:output method="html" indent="yes"/>
> <xsl:template match="/">
> <xsl:apply-templates select="Food_List/Main_Food_List/Main_Course"/>
> <xsl:apply-templates select="Food_List/Side_Dish"/>
> <xsl:apply-templates select="Food_List/Desert/Fancy_Desert"/>
> 
> <xsl:template match="Main_Course">
> <TR><TD>Main Course:</TD><TD xsl:value-of select="."/></TD></TR>
> </xsl:template>
> 
> <xsl:template match="Side_Dish">
> <TR><TD>Side Dish:</TD><TD xsl:value-of select="."/></TD></TR>
> </xsl:template>
> 
> <xsl:template match="Fancy_Desert">
> <TR><TD>Desert:</TD><TD xsl:value-of select="."/></TD></TR>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> 
> Required HTML Output
> <TABLE>
> <TR><TD colspan="2">MENU</TD></TR>
> <TR><TD class="oddRowStyle">Main Dish:</TD><TD
class="oddRowStyle">Chicken</TD></TR>
> <TR><TD class="evenRowStyle">Side Dish:</TD><TD
class="oddRowStyle">Potatoes</TD></TR>
> <TR><TD class="oddRowStyle">Desert:</TD><TD
class="oddRowStyle">Chocolate Truffles</TR>
> </TABLE>


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


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.