<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:output method="html"/>
<xsl:variable name="counter">0</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="//Dispatch/Resource">
<div id="{RESOURCE_ID}" class="jobs">
<xsl:apply-templates select="//Dispatch/Operation">
<xsl:with-param name="resourceid" select="RESOURCE_ID" />
<xsl:with-param name="desc" select="DESCRIPTION" />
</xsl:apply-templates>
</div>
</xsl:template>
<xsl:template match="//Dispatch/Operation">
<xsl:param name="resourceid" />
<xsl:param name="desc" />
<xsl:if test="RESOURCE_ID = $resourceid">
<p class='pagebreakhere'></p>
<table width="600">
<caption>
<table>
<tr>
<td>#<xsl:value-of select="WORKORDER_BASE_ID"/></td>
<td><xsl:value-of select="WORKORDER_LOT_ID"/></td>
<td><xsl:value-of select="WORKORDER_SPLIT_ID"/></td>
<td><xsl:value-of select="WORKORDER_SUB_ID"/></td>
<td><xsl:value-of select="CUSTOMER_NAME"/></td>
</tr>
</table>
</caption>
<tbody>
<tr>
<td>
<table class="heading">
<thead>
<tr>
<th>Resource ID</th>
<th>Resource Description</th>
<th>Start Date</th>
<th>Finish Date</th>
<th>Setup</th>
<th>Run</th>
<th>Reported Hours</th>
<th>Remaining Hours</th>
<th>Qty</th>
<th>Completed Qty</th>
<th>Remaining Qty</th>
</tr>
</thead>
<tbody>
<tr>
<td><xsl:value-of select="$resourceid"/></td>
<td><xsl:value-of select="$desc"/></td>
<td><xsl:call-template name="formatDate">
<xsl:with-param name="given" select="START_DATE" />
</xsl:call-template>
<!--<xsl:value-of select="START_DATE"/>!--></td>
<td><xsl:call-template name="formatDate">
<xsl:with-param name="given" select="FINISH_DATE" />
</xsl:call-template>
<!--<xsl:value-of select="FINISH_DATE"/>!--></td>
<td><xsl:value-of select="SETUP_HRS"/></td>
<td><xsl:value-of select="RUN_HRS"/></td>
<td><xsl:value-of select="ACT_SETUP_HRS + ACT_RUN_HRS" /></td>
<td><xsl:value-of select='format-number(((SETUP_HRS + RUN_HRS) -(ACT_SETUP_HRS + ACT_RUN_HRS)),"#.00")' /></td>
<td><xsl:value-of select="CALC_START_QTY"/></td>
<td><xsl:value-of select="COMPLETED_QTY"/></td>
<td>
<xsl:value-of select='format-number((CALC_START_QTY - COMPLETED_QTY),"#.00")' /></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table>
<thead>
<tr>
<th>Workorder ID</th>
<th>Part ID - Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><xsl:value-of select="WORKORDER_BASE_ID"/>-<xsl:value-of select="WORKORDER_LOT_ID"/>/<xsl:value-of select="WORKORDER_SUB_ID"/></td>
<td>PART ID - Description</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tbody>
<tr>
<th>Engineered By:</th><td><xsl:value-of select="WORKORDER_ENGINEERED_BY"/></td>
<th>Operation Seq:</th><td><xsl:value-of select="SEQUENCE_NO"/></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<th valign="top">Description:</th>
<td><xsl:value-of select="OPERATION_SPEC"/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td class="barcode">*%2<xsl:value-of select="WORKORDER_BASE_ID"/>$<xsl:value-of select="WORKORDER_LOT_ID"/>$<xsl:value-of select="WORKORDER_SPLIT_ID"/>$<xsl:value-of select="WORKORDER_SUB_ID"/>$<xsl:value-of select="SEQUENCE_NO"/>%*</td>
<td>
<table>
<tr>
<th>Prev OP:</th><td>RES</td><th>Qty:</th><td>1</td>
</tr>
<tr>
<th>Next:</th><td colspan="3">RES</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
Quality Op Inspection done?   Yes  No<br /><br />
Inspected by:_____________________________ Date:___________ Double checked by:__________________________<br />
(Be sure to document Inspection on this dispatch, the print/sketch or an inspection form.)
</td>
</tr>
<tr>
<td>
<table>
<thead>
<tr>
<th>Main Resource</th>
<th>Concurrent Resource(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td><xsl:value-of select="MAIN_RESOURCE"/></td>
<td><xsl:value-of select="CONCURRENT"/></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<hr />
<xsl:apply-templates select="//Dispatch/Requirement">
<xsl:with-param name="scheduleid" select="SCHEDULE_ID" />
<xsl:with-param name="workordertype" select="WORKORDER_TYPE" />
<xsl:with-param name="workorderbaseid" select="WORKORDER_BASE_ID" />
<xsl:with-param name="workorderlotid" select="WORKORDER_LOT_ID" />
<xsl:with-param name="workordersplitid" select="WORKORDER_SPLIT_ID" />
<xsl:with-param name="workordersubid" select="WORKORDER_SUB_ID" />
<xsl:with-param name="sequenceno" select="SEQUENCE_NO" />
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<xsl:template match="//Dispatch/Requirement">
<xsl:param name="scheduleid" />
<xsl:param name="workordertype" />
<xsl:param name="workorderbaseid" />
<xsl:param name="workorderlotid" />
<xsl:param name="workordersplitid" />
<xsl:param name="workordersubid" />
<xsl:param name="sequenceno" />
<xsl:if test="SCHEDULE_ID = $scheduleid">
<xsl:if test="WORKORDER_TYPE = $workordertype">
<xsl:if test="WORKORDER_BASE_ID = $workorderbaseid">
<xsl:if test="WORKORDER_LOT_ID = $workorderlotid">
<xsl:if test="WORKORDER_SPLIT_ID = $workordersplitid">
<xsl:if test="WORKORDER_SUB_ID = $workordersubid">
<xsl:if test="SEQUENCE_NO = $sequenceno">
<table width="600px" calss="heading">
<thead>
<tr>
<th>Req Part ID</th>
<th>Piece No</th>
<th>Qty Required</th>
<th>Issued Qty</th>
<th>Whs ID</th>
<th>Whs Qty</th>
</tr>
</thead>
<tbody>
<tr align="center">
<td><xsl:value-of select="PART_ID"/></td>
<td><xsl:value-of select="PIECE_NO"/></td>
<td><xsl:value-of select="CALC_QTY"/></td>
<td><xsl:value-of select="ISSUED_QTY"/></td>
<td><xsl:value-of select="PRIMARY_WHS_ID"/></td>
<td><xsl:value-of select="QTY_ON_HAND"/></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="5" class="barcode" width="85%">*%2<xsl:value-of select="WORKORDER_BASE_ID"/>$<xsl:value-of select="WORKORDER_LOT_ID"/>$<xsl:value-of select="WORKORDER_SPLIT_ID"/>$<xsl:value-of select="WORKORDER_SUB_ID"/>$<xsl:value-of select="SEQUENCE_NO"/>$<xsl:value-of select="PIECE_NO"/>%*</td>
<td><xsl:value-of select="DESCRIPTION"/></td>
</tr>
<tr>
<td colspan="6"><xsl:value-of select="REQUIREMENT_SPEC"/></td>
</tr>
</tfoot>
</table>
<hr />
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="formatDate">
<!-- variable name: given, alias x -->
<xsl:param name="given"/>
<xsl:variable name="y" select="substring-before($given,'T')" />
<xsl:variable name="CCYY" select="substring-before($y,'-')" />
<xsl:variable name="tmp" select="substring-after($y,'-')" />
<xsl:variable name="MM" select="substring-before($tmp,'-')" />
<xsl:variable name="DD" select="substring-after($tmp,'-')" />
<xsl:variable name="z" select="substring-after($given,'T')" />
<xsl:variable name="hh" select="substring-before($z,':')" />
<xsl:variable name="tmp2" select="substring-after($z,':')" />
<xsl:variable name="mm" select="substring-before($tmp2,':')" />
<xsl:variable name="tmp3" select="substring-after($tmp2,':')" />
<xsl:variable name="hh_norm">
<xsl:choose>
<xsl:when test="$hh > 12">
<xsl:value-of select="$hh - 12" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$hh" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="sffx">
<xsl:choose>
<xsl:when test="$hh > 12">
<xsl:value-of select="'pm'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'am'" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="mm_norm" select="$mm" />
<xsl:variable name="result" select="concat($MM,'/',$DD,'/',$CCYY,' ',$hh_norm,':',$mm_norm,' ',$sffx)" />
<!-- display result here -->
<xsl:value-of select="$result" />
</xsl:template>
</xsl:stylesheet>