473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

XML/XSL linebreak in loop

1
I have a XML file created by an employee schedule program. The XML file contains all the data for all the employees and their shifts. I would like to publish the schedule on our intranet, but I’m having some difficulties.

I’ am using a XLST file to format the XML schedule data in to HTML tables. I would like to have a empty(blank) line between each diffrent employee.

The next employee name comes directly after the one before, I would like a line break between each different employee. (That would make the whole schedule much easier to read/view)

So far what I’ve got is just a simple XSLT for-each loop.

For example the XML file looks like this:
Expand|Select|Wrap|Line Numbers
  1. <shift>
  2.    <EmployeeName>John</EmployeeName>    
  3.    <shiftdate>2006-05-05</shiftdate>
  4.    <starttime>06:00</ starttime>
  5.    <endtime>12:00</ endtime>
  6. </shift>
  7. <shift>
  8.    <EmployeeName>John</EmployeeName>    
  9.    <shiftdate>2006-05-06</shiftdate>
  10.    <starttime>06:00</ starttime>
  11.    <endtime>12:00</ endtime>
  12. </shift>
  13. <shift>
  14. <EmployeeName>John</EmployeeName>    
  15.    <shiftdate>2006-05-07</shiftdate>
  16.    <starttime>09:00</ starttime>
  17.    <endtime>18:00</ endtime>
  18.    </shift>
  19. <shift>
  20. <EmployeeName>Erik</EmployeeName>    
  21.    <shiftdate>2006-05-08</shiftdate>
  22.    <starttime>08:00</ starttime>
  23.    <endtime>14:00</ endtime>
  24. </shift>
And the XSL file:
Expand|Select|Wrap|Line Numbers
  1.  <table>
  2.     <tr>
  3.         <td>Name</td> 
  4.         <td>date</td>
  5.         <td>Start </td>
  6.         <td>end -time</td>
  7.     </tr>
  8.         <xsl:for-each select="shift">
  9.             <xsl:sort select="EmployeeName" />
  10.         <tr>
  11.             <td>
  12.             <xsl:value-of select="EmployeeName" /> 
  13.             </td>
  14.             <td>
  15.             <xsl:value-of select="substring(shiftdate, 9, 2)"/> -
  16.             <xsl:value-of select="substring(shiftdate, 6, 2)"/> -
  17.             <xsl:value-of select="substring(shiftdate, 1, 4)"/>
  18.             </td>
  19.             <td>
  20.             <xsl:value-of select="starttime" /> -
  21.             </td>
  22.             <td>
  23.             <xsl:value-of select="endtime" /> 
  24.             </td>
  25.         </tr>
  26.         </xsl:for-each>
  27. </table> 
And it comes out like this:

Expand|Select|Wrap|Line Numbers
  1. Name         date             start end -time
  2. John          2006-05-05     06:00-12:00
  3. John          2006-05-05     06:00-12:00
  4. John          2006-05-05     09:00-18:00
  5. Erik          2006-05-06     08:00-14:00
  6. Erik          2006-05-07     06:00-12:00
  7. Nick          2006-05-05     12:00-20:00
  8. Nick          2006-05-06     14:00-22:00
  9. Nick          2006-05-07     14:00-22:00
  10. Mary          2006-05-05     10:00-20:00
  11.  
What i would like as an output:
Expand|Select|Wrap|Line Numbers
  1. Name         date             start end -time
  2. John          2006-05-05     06:00-12:00
  3. John          2006-05-05     06:00-12:00
  4. John          2006-05-05     09:00-18:00
  5.  
  6. Erik          2006-05-06     08:00-14:00
  7. Erik          2006-05-07     06:00-12:00
  8.  
  9. Nick          2006-05-05     12:00-20:00
  10. Nick          2006-05-06     14:00-22:00
  11. Nick          2006-05-07     14:00-22:00
  12.  
  13. Mary          2006-05-05     10:00-20:00
I'am playing around with:
Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="preceding::EmployeeName!= EmployeeName">
  2. <br />
  3. </xsl:if> 
  4.  
But so far no succes. Is there anyone how can guide me in the right direction?
Aug 11 '06 #1
1 2976
iam_clint
1,208 Expert 1GB
since your working with tables to do a line beak why not just go ahead and add an extra

Expand|Select|Wrap|Line Numbers
  1. <tr><td colspan="3">&nbsp;</tr></td>
then if the preceding name does not = the current name then add that break just like you are. i don't happen to know the xml code for checking this.. maybe someone more familiar with XML will post a reply for that.

Good luck
Aug 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: nAmYzArC | last post by:
Hi everyone, I'm setting the body of an email using values from a form firstname = bob lastname = dole ebody = 'First Name: ' + firstname + '\r\n' + 'Last Name: ' + lastname ...
3
by: Jim | last post by:
When output from inside a loop <xsl:for-each select="Comment"> <br><xsl:value-of select="Line" /></br> </xsl:for-each> A blank line is inserted between each line, when I remove the <br> then...
4
by: Dirk Reske | last post by:
Hey, I have following struct: struct Packet { string Command; byte data; }
2
by: Georg Weiler | last post by:
Hi, I have a form, where the user enters text. After submit, the text is then inserted into a PostgreSQL database. So far, so good. The problem is, that most of my users copy&paste their text...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
3
by: Michael Hamm | last post by:
My page http://www.math.wustl.edu/~msh210/whatsnew.xml (with XSLT and CSS adding formatting) has a paragraph-type break after "Subscribe to this feed" which, afaIct looking at the source code,...
3
by: Per W. | last post by:
Hi, is it possible to have Literal using linebreaks? If i have a textfile with more than 1 line then Literal take all on one line. /Per W.
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
4
by: agun | last post by:
Hello, Hi, i'm really a newbie in programming, especially javascript. I have one question in my mind right now. Sorry before if i'm not clear. Please see this example: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.