Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="xml" encoding="utf-8" indent="yes" />
- <xsl:template name="css">
- <style>
- <xsl:attribute name="type">
- <xsl:text>text/css</xsl:text>
- </xsl:attribute>
- <xsl:text>table{border-collapse: collapse;font-size: 11px;font-family: Arial;border-spacing: 0px;}caption{text-align:left;}td,th{border: 1px solid black;}.date{width:100px;white-space:nowrap;}.number{text-align:right;}#footer{font-size:11px;}#signature{font-size:11px;}</xsl:text>
- </style>
- </xsl:template>
- <xsl:template name="header">
- <xsl:param name="title" />
- <xsl:param name="name" />
- <xsl:param name="surname" />
- <xsl:param name="text" />
- <p><xsl:value-of select="$title" /><xsl:text> </xsl:text> <xsl:value-of select="$name" /><xsl:text> </xsl:text> <xsl:value-of select="$surname" /><xsl:text>,</xsl:text></p><!-- mettre maj a la premiere lettre -->
- <p>Veuillez trouver ci-dessous <xsl:value-of select="$text" /></p>
- </xsl:template>
- <xsl:template name="footer">
- <div id="footer">
- <p><xsl:text>Cet email vous est envoyé automatiquement par le système de prestations ICTCG.</xsl:text></p>
- <p><xsl:text>En cas de question, n'hésitez pas à nous contacter.</xsl:text></p>
- </div>
- </xsl:template>
- <xsl:template name="signature">
- <div id="signature">
- <p>---</p>
- <p>ICTCG s.a / GWEB sprl</p>
- <p>http://www.ictcg.com / http://www.gweb.be</p>
- <p>+352.27.86.21.00 / +32.4.345.05.42</p>
- </div>
- </xsl:template>
- </xsl:stylesheet>
- ------
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xsl:import href="generate-mail-template.xsl" />
- <xsl:output method="xml" encoding="utf-8" indent="yes" />
- <!-- take a list of event and calculate the global amount -->
- <xsl:template name="sum">
- <xsl:param name="events" />
- <xsl:param name="sum" select="0" />
- <xsl:variable name="curr" select="$events[1]" />
- <xsl:choose>
- <!-- If there's at least one event on the list, we calculate its duration and give it the the sum variable -->
- <!-- and call this template until there's no more event on the list -->
- <xsl:when test="$curr">
- <xsl:variable name="start" select="$curr/start/datetime" />
- <xsl:variable name="end" select="$curr/end/datetime" />
- <xsl:variable name="starthour" select="hours-from-dateTime($start)" />
- <xsl:variable name="endhour" select="hours-from-dateTime($end)" />
- <xsl:variable name="eventduration" select="$sum + ($endhour - $starthour)" />
- <xsl:call-template name="sum">
- <xsl:with-param name="events" select="$events[position() > 1]" />
- <xsl:with-param name="sum" select="$eventduration" />
- </xsl:call-template>
- </xsl:when>
- <!-- If there's no more event we return the calculated sum -->
- <xsl:otherwise>
- <xsl:value-of select="$sum" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- called template in generate-main -->
- <xsl:template name="leaves">
- <leaves>
- <!-- to be detected by the servlet, mails must be in an 'emails' node -->
- <emails>
- <email>
- <head>
- <subject><xsl:text>ICTCG - </xsl:text><xsl:value-of select="/workfile/query/@year" /><xsl:text>-</xsl:text><xsl:value-of select="/workfile/query/@month" /><xsl:text> - Timesheet - Leaves</xsl:text></subject>
- <from><xsl:value-of select="/workfile/query/parameter[@name='sender-mail']/@value" /></from>
- <recipient><xsl:value-of select="/workfile/query/customer[@internal='true']/email[@type='production']/@address" /></recipient>
- <cc><xsl:value-of select="/workfile/query/customer[@internal='true']/email[@type='production']/@cc" /></cc>
- </head>
- <body>
- <xsl:attribute name="type">
- <xsl:text>text/xhtml</xsl:text>
- </xsl:attribute>
- <html>
- <head>
- <xsl:call-template name="css" />
- </head>
- <body>
- <!-- call the template header to write the header of mail body (see generate-mail-template.xsl) -->
- <xsl:variable name="text">
- <xsl:text>le tableau journalier des absences, ainsi que le tableau récapitulatif pour le mois:</xsl:text>
- </xsl:variable>
- <xsl:call-template name="header">
- <xsl:with-param name="title" select="/workfile/query/customer[@internal='true']/email[@type='admin']/@title" />
- <xsl:with-param name="name" select="/workfile/query/customer[@internal='true']/email[@type='admin']/@name" />
- <xsl:with-param name="surname" select="/workfile/query/customer[@internal='true']/email[@type='admin']/@surname" />
- <xsl:with-param name="text" select="$text" />
- </xsl:call-template>
- <!-- table for the daily recap -->
- <table>
- <caption><i>Récapitulatif journalier</i></caption>
- <tr>
- <th>Date</th>
- <th>Jour</th>
- <th>Consultant</th>
- <th>Client</th>
- <th>Type</th>
- <th class="number">Dur�E9;e (h)</th>
- </tr>
- <!-- to sort correctly by date, first, we write in several tr the recap -->
- <!-- then we apply a template to sort correctly this result -->
- <xsl:variable name="vPass1">
- <unsortedLines>
- <!-- for each customer where is considered like internal and where their task has an amount of hours bigger than 0 -->
- <xsl:for-each select="/workfile/timesheet/customers/customer[@id=/workfile/query/customer[@internal='true']/@id]/task[@hours > 0]">
- <xsl:for-each select="consultant">
- <xsl:variable name="customer" select="../.." />
- <xsl:variable name="task" select=".." />
- <xsl:variable name="consultant" select="." />
- <!-- we're going to calculate the amount of hours for a task considered all events for this day -->
- <xsl:for-each select="/workfile/calendar-list/calendar[@id=$consultant/@calendar-id]
- /items/event[upper-case(summary)=$task/@code]">
- <xsl:variable name="position" select="position()" />
- <xsl:variable name="startDate" select="substring-before(start/datetime,'T')" />
- <xsl:variable name="task-code" select="summary" />
- <!-- 'previousevents' is used to know if this event is the first of the day for a task -->
- <!-- if it's not, we've already calculate the amount of this task for this day and show it on the table -->
- <xsl:variable name="previousevents" select="preceding-sibling::event[$startDate=substring-before(start/datetime,'T')
- and upper-case(summary)=$task-code
- and position() < $position]" />
- <xsl:variable name="events" select="/workfile/calendar-list/calendar[@id=$consultant/@calendar-id]
- /items/event[upper-case(summary)=$task/@code
- and substring-before(start/datetime,'T')=$startDate]" />
- <xsl:variable name="result">
- <xsl:call-template name="sum">
- <xsl:with-param name="events" select="$events" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="not($previousevents or $previousevents='')">
- <xsl:if test="$result > 0">
- <tr>
- <td class="startdate"><xsl:value-of select="$startDate" /></td>
- <td><xsl:value-of select="custom-elements/day-of-week[@lang='FR']" /></td>
- <td><xsl:value-of select="$consultant/@code" /></td>
- <td><xsl:value-of select="$customer/@id" /></td>
- <td><xsl:value-of select="upper-case(summary)" /></td>
- <td style="text-align:right;"><xsl:value-of select="format-number($result, '#.00')" /></td>
- </tr>
- </xsl:if>
- </xsl:if>
- </xsl:for-each>
- </xsl:for-each>
- </xsl:for-each>
- </unsortedLines>
- </xsl:variable>
- <!-- we call the sorting template -->
- <!-- and transform the result in 'unsortedLines -->
- <xsl:apply-templates select="$vPass1/*" />
- </table>
- <p></p>
- <!-- recap for the month -->
- <table>
- <xsl:attribute name="border">
- <xsl:text>1</xsl:text>
- </xsl:attribute>
- <caption><i>Résumé du mois</i></caption>
- <tr>
- <th>Client</th>
- <th>Consultant</th>
- <th>Type</th>
- <th class="number">Durée (h)</th>
- </tr>
- <!-- for each customer where is considered like internal and where their task has an amount of hours bigger than 0 -->
- <xsl:for-each select="/workfile/timesheet/customers/customer[@id=/workfile/query/customer[@internal='true']/@id]
- /task[@hours > 0]">
- <xsl:variable name="taskcodetwo" select="./@code" />
- <xsl:for-each select="consultant">
- <xsl:variable name="cons" select="." />
- <xsl:variable name="event-list" select="/workfile/calendar-list/calendar[@id=$cons/@calendar-id]/items
- /event[upper-case(summary)=$taskcodetwo]" />
- <xsl:variable name="total">
- <xsl:call-template name="sum">
- <xsl:with-param name="events" select="$event-list" />
- </xsl:call-template>
- </xsl:variable>
- <!-- we only show table line for tasks bigger than 0 -->
- <xsl:if test="$total > 0">
- <tr>
- <td><xsl:value-of select="../../@id" /></td>
- <td><xsl:value-of select="@code" /></td>
- <td><xsl:value-of select="../@code" /></td>
- <td class="number"><xsl:value-of select="format-number($total, '#.00')" /></td>
- </tr>
- </xsl:if>
- </xsl:for-each>
- </xsl:for-each>
- </table>
- <p></p>
- <xsl:call-template name="footer" />
- <xsl:call-template name="signature" />
- </body>
- </html>
- </body>
- </email>
- </emails>
- </leaves>
- </xsl:template>
- <!-- sorting template -->
- <xsl:template match="unsortedLines">
- <xsl:perform-sort select="*">
- <xsl:sort select="day-from-date(xs:date(td[@class='startdate']))" />
- </xsl:perform-sort>
- </xsl:template>
- </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement