View Single Post
  #2 (permalink)  
Old October 22nd, 2010, 09:06 AM
CCPuser CCPuser is offline
Registered User
Points: 29, Level: 1
Points: 29, Level: 1 Points: 29, Level: 1 Points: 29, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Solutions

XSL V 1.0 based solution:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:key name="transitGroup" match="row[DeliveryMode='TRANSIT']" use="concat(StackNumber,BlockNumber,LocationCode)"/>

<xsl:template match="/">
<xsl:apply-templates select="Output" />
</xsl:template>

<xsl:template match="Output">
<Output>
<xsl:apply-templates select="row[DeliveryMode='TRANSIT']" mode="special"/>
</Output>
</xsl:template>

<xsl:template match="row[DeliveryMode='TRANSIT']" mode="special">
<xsl:if test="generate-id(.)=generate-id(key('transitGroup', concat(StackNumber,BlockNumber,LocationCode))[1])">
<xsl:for-each select="key('transitGroup', concat(StackNumber,BlockNumber,LocationCode))">
<xsl:sort select="BookVersion" data-type="number" order="descending" />
<xsl:choose>
<xsl:when test="position() = 1">
<xsl:call-template name="display" />
</xsl:when>
<xsl:otherwise>
<!-- do nothing -->
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:if>
</xsl:template>

<xsl:template name="display">
<row>
<StackNumber>
<xsl:value-of select="StackNumber"/>
</StackNumber>
<BlockNumber>
<xsl:value-of select="BlockNumber"/>
</BlockNumber>
<LocationCode>
<xsl:value-of select="LocationCode"/>
</LocationCode>
<StoreNumber>
<xsl:value-of select="StoreNumber"/>
</StoreNumber>
<BookVersion>
<xsl:value-of select="BookVersion" />
</BookVersion>
</row>
</xsl:template>

</xsl:stylesheet>

2) Version 2.0 Based solution:

<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xsd"
version="2.0">

<xsl:output indent="yes"/>

<xsl:template match="/">
<Output>
<xsl:for-each-group select="*/row[DeliveryMode='TRANSIT']"
group-by="concat(StackNumber,'&#xd;',
BlockNumber,'&#xd;',LocationCode)">
<xsl:for-each select="current-group()
[xsd:decimal(BookVersion)=
max(current-group()/BookVersion/xsd:decimal(.))]
[1]">
<row>
<xsl:copy-of select="* except DeliveryMode"/>
</row>
</xsl:for-each>
</xsl:for-each-group>
</Output>
</xsl:template>

</xsl:stylesheet>
Reply With Quote