Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2009, 11:57 AM
Ann Ann is offline
Registered User
 
Join Date: Apr 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Modyfing the code

Hi,

I'd like to ask for help in modyfing my XSL code. Here is it:


Code:
<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet  version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html><body scroll="no" bgcolor="lightgreen"><font size="1pt"><center>
<br></br><br></br>
<p><b><u><font size="2">TIMETABLE</font></u></b></p>
<p>Studies: <b>full-time</b></p>
<p>Academic year: <b>2008/2009</b></p>
<p>Semester: <b>summer</b></p>
<br></br>
<table border="2" width="60%" height="25%" bgcolor="lightgrey">
<tr>
<th><font size="1pt"><center>Monday</center></font></th>
<th><font size="1pt"><center>Subject</center></font></th>
<th><font size="1pt"><center>Form</center></font></th>
<th><font size="1pt"><center>Room</center></font></th>
</tr>
 
<xsl:for-each select="semester/day_1">
<tr>
 
 
  <xsl:choose>
 
                        <xsl:when test="@subject='Gymnastics'">
                               <xsl:attribute name="style">background-color:lightyellow; 
                               </xsl:attribute>
                         </xsl:when>
                         <xsl:when test="@subject='Object programming'">
                               <xsl:attribute name="style">background-color:lightblue; 
                               </xsl:attribute>
                         </xsl:when>
                         <xsl:otherwise>
                                    <xsl:attribute name="style">background-color:lightgreen; 
          </xsl:attribute>
                        </xsl:otherwise>
  </xsl:choose>
 
  <xsl:choose>
 
   <xsl:when test="@form='lecture'">
                               <xsl:attribute name="style">font-weight:bold;
                              </xsl:attribute>
                         </xsl:when>
                         <xsl:when test="@form='lab'">
                               <xsl:attribute name="style">font-style:italic; 
                               </xsl:attribute>
                         </xsl:when>
 
   <xsl:when test="@form ='classes'">
                                    <xsl:attribute name="style">text-decoration:underline; 
          </xsl:attribute>
                            </xsl:when>
  </xsl:choose>
 
 
<td width="20%"><font size="1pt"><center><xsl:value-of select="hour"/></center></font></td>
<td width="35%"><font size="1pt"><xsl:value-of select="@subject"/></font></td>
<td width="15%"><font size="1pt"><center><xsl:value-of select="@form"/></center></font></td>
<td width="15%"><font size="1pt"><center><xsl:value-of select="room"/></center></font></td>
 
</tr>
</xsl:for-each>
</table>
<br></br>
<br></br>
 
 
<table border="2" width="60%" height="25%" bgcolor="lightgrey">
<tr>
<th><font size="1pt"><center>Tuesday</center></font></th>
<th><font size="1pt"><center>Subject</center></font></th>
<th><font size="1pt"><center>Form</center></font></th>
<th><font size="1pt"><center>Room</center></font></th>
</tr>
<xsl:for-each select="semester/day_2">
<tr>
<td width="20%"><font size="1pt"><center><xsl:value-of select="hour"/></center></font></td>
<td width="35%"><font size="1pt"><xsl:value-of select="subject"/></font></td>
<td width="15%"><font size="1pt"><center><xsl:value-of select="form"/></center></font></td>
<td width="15%"><font size="1pt"><center><xsl:value-of select="room"/></center></font></td>
</tr>
</xsl:for-each>
</table>
</center>
</font>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

My XML:

Code:
<?xml version="1.0" encoding ="windows-1250"?>
<?xml-stylesheet type="text/xsl" href="details.xsl"?>
<!DOCTYPE semester SYSTEM "semester.dtd">
<semester>
 
<day_1 form="lecture" subject ="Gymnastics">
<hour>8.00 - 9.30</hour>
<room>145C</room>
</day_1>
<day_1 form="lab" subject="Object programming">
<hour>9.45 - 11.15</hour>
<room>427</room>
</day_1>
<day_1 form="classes" subject="Team sports">
<hour>11.45 - 13.15</hour>
<room>court</room>
</day_1>
 
<day_2>
<hour>8.00 - 9.30</hour>
<subject>Databases</subject>
<form>lecture</form>
<room>458D</room>
</day_2>
<day_2>
<hour>10.00 - 11.30</hour>
<subject>Team sports</subject>
<form>classes</form>
<room>court</room>
</day_2>
<day_2>
<hour>11.45 - 13.15</hour>
<subject>Object programming</subject>
<form>classes</form>
<room>78C</room>
</day_2>
</semester>
and finally DTD:

Code:
<?xml version="1.0" encoding="ISO-8859-2"?>
<!ELEMENT semester (day_1,day_2)>
<!ELEMENT day_1 (hour, room)>
<!ELEMENT day_2 (hour, room)>
<!ATTLIST day_1
        form (lecture | lab |classes) #REQUIRED
        subject (Gymnastics|Object_programming|Team_sports) #REQUIRED
>
<!ELEMENT hour (#PCDATA)>
<!ELEMENT room (#PCDATA)>


I am particularly interested in the fragment of XSL code where two instruction of xsl:choose are placed. I assume the way I put them is incorrect as only the second is working.

Here is what I want to achieve:
I have a few subjects and they may be lecture, classes or lab. These forms are formatted:
lecture-bold, lab-italic and classes-underline. And it works.

However I'd like simultaneously format the names of subjects in the following way:
Gymnastics-lightyellow, Object programming-lightblue and Team sports -lightgreen.

Could anybody help me in joining these two kind of formatting?
I would be very grateful for any help.
 
Old April 27th, 2009, 12:09 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT if you try to create two attributes with the same name on the same element, the second one wins. You seem to be expecting that the two values will be concatenated.

To get the concatenation, put all the conditional logic inside xsl:attribute

Code:
<xsl:attribute name="style">
  <xsl:choose>
   <xsl:when test="@subject='Gymnastics'">background-color:lightyellow;</xsl:when> 


etc

__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
Ann (April 27th, 2009)
 
Old April 27th, 2009, 12:22 PM
Ann Ann is offline
Registered User
 
Join Date: Apr 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you, thank you very much. I was looking for a solution so long...
Thank you again.
Regards





Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to save html page source code? Jaymond Flurrie Access VBA 2 July 2nd, 2019 06:04 PM
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.