Report Sort Order
I'm attempting to get a report to sort in ascending or descending order but I get results that are out of order.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sw="http://www.interapptive.com/shipworks" extension-element-prefixes="sw">
<!-- Imports -->
<xsl:import href="System\Snippets" />
<xsl:output method="html" encoding="utf-8" />
<!-- Start of template -->
<xsl:template match="/"><xsl:apply-templates /></xsl:template>
<xsl:template match="ShipWorks">
<!-- Width defined by the template PageSettings -->
<xsl:variable name="pageWidth" select="concat(Template/Output/ContentWidth, 'in')" />
<!-- Default font. Specified as a variable since GMail and Outlook behave differently. -->
<xsl:variable name="pageFont" select="'font-family: Arial; font-size: 8pt;'" />
<!-- These styles are used on multiple td's so to avoid copy\paste errors they are defined once here. We have to do this since GMail doesn't support <style> in the <head>. -->
<xsl:variable name="headerStyle" select="'border: 1px solid dimgray; background-color: #F3F3F3; font-weight: bold; padding: 3px;'" />
<html>
<head>
<title>Order Shipping Cost</title>
<style>
body, table { <xsl:value-of select="$pageFont" /> }
</style>
</head>
<body style="{$pageFont}">
<h3 style="font-size: 1.67em; margin-top: 0;">Order Status Summary</h3>
<table style="width:{$pageWidth}; margin: 10px 0px 0px 0px; border-collapse: collapse;" cellspacing="0">
<tr>
<td style="{$headerStyle};">Connection</td>
<td style="{$headerStyle};">Order</td>
<td style="{$headerStyle};">Date</td>
<td style="{$headerStyle};">Weight/DIM</td>
<td style="{$headerStyle};">Name</td>
<td style="{$headerStyle};">Carrier</td>
<td style="{$headerStyle};">Freight</td>
</tr>
<!-- Group by order number -->
<xsl:for-each select="Customer/Order">
<xsl:sort select="./Shipment/ProcessedDate" order="ascending" data-type="number" />
<xsl:variable name="shipment" select="../../../.." />
<!-- We shouldn't have to conditionally apply the topborder... but IE is broken. -->
<xsl:variable name="rowStyle">
padding: 4px 8px 4px 8px;
<xsl:if test="position() != 1">border-top: 1px solid lightgrey;</xsl:if>
</xsl:variable>
<tr>
<td style="{$rowStyle}">
<xsl:variable name="order" select="." />
<xsl:variable name="store" select="/ShipWorks/Store[@ID = $order/@storeID]" />
<xsl:value-of select="$store/StoreName" />
</td>
<td style="{$rowStyle}">
<!-- Shared Snippet -->
<xsl:call-template name="OrderNumber">
<xsl:with-param name="order" select="." />
</xsl:call-template>
<xsl:variable name="ship" select="Address[@type='ship']" /><br />
<xsl:text>Residential: </xsl:text><xsl:value-of select="Address[@type='ship']/ResidentialStatus" />
</td>
<xsl:variable name="SWProcessedDate" select="Shipment[Processed='true']/ProcessedDate" />
<xsl:variable name="result">
<xsl:call-template name="UTC-minus-Eight">
<xsl:with-param name="dateTime" select="$SWProcessedDate" />
<!-- UTC Time Zone setting for Pacific Standard Time -->
<xsl:with-param name="timeZone" select="-7" />
</xsl:call-template>
</xsl:variable>
<td style="{$rowStyle}"><xsl:value-of select="substring-before($result, 'T')"/><br /><xsl:value-of select="substring-before(substring-before(substring-after($result, 'T'), 'Z'),'.')"/></td>
<td style="{$rowStyle}"><xsl:value-of select="./Shipment/TotalWeight" /><br />
<xsl:value-of select="./Shipment/Package/Dimensions/Length" /><xsl:text> </xsl:text><xsl:value-of select="./Shipment/Package/Dimensions/Width" /><xsl:text> </xsl:text><xsl:value-of select="./Shipment/Package/Dimensions/Height" /></td>
<td style="{$rowStyle}"><xsl:value-of select="Address[@type='bill']/LastName" />, <xsl:value-of select="Address[@type='bill']/FirstName" /><br />
<xsl:value-of select="Address[@type='bill']/Line1" /><br />
<xsl:value-of select="Address[@type='bill']/City" />,<xsl:value-of select="Address[@type='bill']/StateCode" /><xsl:text> </xsl:text><xsl:value-of select="Address[@type='bill']/PostalCode" /><br />
</td>
<td style="{$rowStyle}"><xsl:value-of select="./Shipment/ServiceUsed" /><br />
<xsl:value-of select="./Shipment/ShipmentType" /></td>
<td style="{$rowStyle}"><xsl:value-of select="format-number(./Shipment/TotalCharges,'#.00')" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Snippet code
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<!-- Start of snippet -->
<xsl:template name="UTC-minus-Eight">
<xsl:param name="dateTime"/>
<xsl:param name="timeZone"/>
<xsl:variable name="date" select="substring-before($dateTime, 'T')" />
<!--<xsl:variable name="time" select="substring-before(substring-after($dateTime, 'T'), 'Z')" /> -->
<xsl:variable name="time" select="substring-before(substring-after($dateTime, 'T'), 'Z')" />
<xsl:variable name="year" select="substring($date, 1, 4)" />
<xsl:variable name="month" select="substring($date, 6, 2)" />
<xsl:variable name="day" select="substring($date, 9, 2)" />
<xsl:variable name="hour" select="substring($time, 1, 2)" />
<xsl:variable name="minute" select="substring($time, 4, 2)" />
<xsl:variable name="second" select="substring($time, 7)" />
<xsl:variable name="a" select="floor((14 - $month) div 12)"/>
<xsl:variable name="y" select="$year + 4800 - $a"/>
<xsl:variable name="m" select="$month + 12*$a - 3"/>
<xsl:variable name="jd" select="$day + floor((153*$m + 2) div 5) + 365*$y + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045" />
<!-- This is where the TimeZone is adjusted by the UTC Time Zone value -->
<xsl:variable name="total-seconds" select="86400*$jd + 3600*$hour + 60*$minute + $second + ($timeZone * 60 * 60)" />
<xsl:variable name="new-jd" select="floor($total-seconds div 86400)"/>
<xsl:variable name="new-hour" select="floor($total-seconds mod 86400 div 3600)"/>
<xsl:variable name="new-minute" select="floor($total-seconds mod 3600 div 60)"/>
<xsl:variable name="new-second" select="$total-seconds mod 60"/>
<xsl:variable name="f" select="$new-jd + 1401 + floor((floor((4 * $new-jd + 274277) div 146097) * 3) div 4) - 38"/>
<xsl:variable name="e" select="4*$f + 3"/>
<xsl:variable name="g" select="floor(($e mod 1461) div 4)"/>
<xsl:variable name="h" select="5*$g + 2"/>
<xsl:variable name="D" select="floor(($h mod 153) div 5 ) + 1"/>
<xsl:variable name="M" select="(floor($h div 153) + 2) mod 12 + 1"/>
<xsl:variable name="Y" select="floor($e div 1461) - 4716 + floor((14 - $M) div 12)"/>
<xsl:value-of select="concat($Y, format-number($M, '-00'), format-number($D, '-00'))"/>
<xsl:text>T</xsl:text>
<xsl:value-of select="concat(format-number($new-hour, '00'), format-number($new-minute, ':00'), format-number($new-second, ':00.###'),'Z')"/>
<!-- <xsl:text>-08:00</xsl:text> -->
</xsl:template>
</xsl:stylesheet>
Please sign in to leave a comment.
Comments
0 comments