XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 9th, 2001, 09:07 PM
sunnychan's Avatar
sunnychan sunnychan is offline
a lazy guy
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: Hong Kong
Posts: 99 sunnychan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Question XSL problem

Hello,

I'm trying to use XSL to display different color in each row of the table. But the method I used below does not work. Any idea?

(In HTML)
<TABLE>
<TR BGCOLOR="#FFFFFF"><TD>1</TD> ... <TR>
<TR BGCOLOR="#AAAAAA"><TD>2</TD> ... </TR>
<TR BGCOLOR="#FFFFFF"><TD>3</TD> ... </TR>
<TR BGCOLOR="#AAAAAA"><TD>4</TD> ...</TR>
</TABLE>

(In XSL)
<TABLE>
<xsl:for-each select="./Atts/Att">
<xsl:variable name="CHOOSE"><xsl:value-of select="position()"/></xsl:variable>
<xsl:for-each select="./AttFormats/AttFormat">

<tr>
<xsl:choose>
<xsl:when test="$CHOOSE mod 2 = 0">
<xsl:attribute name="bgcolor">#FFFFFF</xsl:attribute>
</xsl:when>
<xsltherwise>
<xsl:attribute name="bgcolor">#AAAAAA</xsl:attribute>
</xsltherwise>
</xsl:choose>
<td><xsl:value-of select=".//somevalue"/></td>
<td>...</td>
</tr>
</xsl:for-each>
</xsl:for-each
</TABLE>

=================================
The variable $CHOOSE seems NOT work with the function 'mod'.

more info:
The XML look like
<Atts>
<Att>
<something></something>
<AttFormats>
<AttFormat>jpg</AttFormat>
<AttFormat>gif</AttFormat>
</AttFormats>
</Att>
<Att>
...
...
</Att>
</Atts>


I need to display each file format (Attformat) in one row inside a table.

Reply With Quote
  #2  
Old August 10th, 2001, 05:44 PM
analogx analogx is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: France
Posts: 2 analogx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to analogx
XSL Help to sunnychan

I think you can try the following XSL stylesheet with your own XML document...
(you must put "bgcolor" attribute into "td" tag only...)

<!-- ************************************* -->
<?xml version='1.0' encoding='iso-8859-1' ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xslutput method="html" indent="yes" encoding="iso-8859-1" media-type="text/html"/>
<!-- ************************************* -->

<xsl:template match="Atts">
<html>
<head>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<!-- ************************************* -->
<xsl:template match="Att">
<table>
<xsl:apply-templates select="AttFormats"/>
</table>
</xsl:template>
<!-- ************************************* -->
<xsl:template match="AttFormats">
<xsl:for-each select="AttFormat">
<xsl:variable name="CHOOSE" select="position()"/>
<tr>
<xsl:choose>
<xsl:when test="$CHOOSE mod 2 = 0">
<xsl:element name="td">
<xsl:attribute name="bgcolor">#FFFFFF</xsl:attribute>
<xsl:value-of select="$CHOOSE"/>
</xsl:element>
</xsl:when>
<xsltherwise>
<xsl:element name="td">
<xsl:attribute name="bgcolor">#AAAAAA</xsl:attribute>
<xsl:value-of select="$CHOOSE"/>
</xsl:element>
</xsltherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</xsl:template>
<!-- ************************************* -->

</xsl:stylesheet>
i hope it will work fine as you want



Regards

Analogx

(don't hesitate to contact me if you need some help...)

Reply With Quote
  #3  
Old August 13th, 2001, 03:27 AM
Serge Serge is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Posts: 1 Serge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It's not the choose...

We're using xalan (Java) to do XSLT. What we found out is that you can only set a xsl:variable ONCE. So when it's set once, it keeps that value. We work around it by determining the value elsewhere and passing it in through xslaram

Reply With Quote
  #4  
Old August 13th, 2001, 05:01 AM
analogx analogx is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: France
Posts: 2 analogx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to analogx
Hello

I don't know Xalan.
i'm using Sablotron with PHP.
Sablotron is a XSLT Processor written in C++ (i think it's greter than Java :-)) ).

For more informations i invite you to see Sablotron homepage
URL

Regards

analogx

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap