The Saxon Help list is intended for problems that are specific to the Saxon product. For general XSLT coding help I recommend using the xsl-list at mulberrytech.com.

You seem to have mail-bombed this question to every mailing list and forum that deals with XSLT. I'm afraid this is a way of making yourself rather unpopular with the volunteers who respond to questions on these lists - there's nothing more frustrating than to spend 20 minutes of your time trying to help someone, only to find that the time is wasted because someone else has already provided an answer in another place. It also means that you are filling the archives of the lists with unanswered questions, which is frustrating to those who come after you with the same question.

Michael Kay
Saxonica

On 21/10/2010 21:11, Peacock Lover wrote:
I would like to group based on fields of row element (combination of StackNumber,BlockNumber and LocationCode) and select only higher BookVersion (BookVersion) based rows in particular group(combination of StackNumber,BlockNumber and LocationCode) and also to select the rows of DeliveryMode with the value as TRANSIT.

Here is the input document

<?xml version="1.0"?>
<Output>
    <row>
        <StackNumber>19</StackNumber>
        <BlockNumber>61001</BlockNumber>
        <DeliveryMode>TRANSIT</DeliveryMode>
        <LocationCode>MON</LocationCode>
        <BookVersion>03</BookVersion>
        <StoreNumber>1010</StoreNumber>

    </row>
    <row>
        <StackNumber>20</StackNumber>
        <BlockNumber>61001</BlockNumber>
        <DeliveryMode>TRANSIT</DeliveryMode>
        <LocationCode>MON</LocationCode>
        <BookVersion>01</BookVersion>
        <StoreNumber>1011</StoreNumber>
    </row>
    <row>
        <StackNumber>20</StackNumber>
        <BlockNumber>61001</BlockNumber>
        <DeliveryMode>TRANSIT</DeliveryMode>
        <LocationCode>MON</LocationCode>
        <BookVersion>02</BookVersion>
        <StoreNumber>1013</StoreNumber>
    </row>
    <row>
        <StackNumber>21</StackNumber>
        <BlockNumber>61001</BlockNumber>
        <DeliveryMode>RECVD</DeliveryMode>
        <LocationCode>MON</LocationCode>
        <BookVersion>03</BookVersion>
        <StoreNumber>1022</StoreNumber>
    </row>
    <row>
        <StackNumber>21</StackNumber>
        <BlockNumber>61001</BlockNumber>
        <DeliveryMode>TRANSIT</DeliveryMode>
        <LocationCode>MON</LocationCode>
        <BookVersion>03</BookVersion>
        <StoreNumber>1022</StoreNumber>
    </row>
    <row>
        <StackNumber>22</StackNumber>
        <BlockNumber>15098</BlockNumber>
        <DeliveryMode>TRANSIT</DeliveryMode>
        <LocationCode>MON</LocationCode>
        <BookVersion>01</BookVersion>
        <StoreNumber>1010</StoreNumber>
    </row>
    <row>
        <StackNumber>22</StackNumber>
        <BlockNumber>22456</BlockNumber>
        <DeliveryMode>TRANSIT</DeliveryMode>
        <LocationCode>MON</LocationCode>
        <BookVersion>02</BookVersion>
        <StoreNumber>1011</StoreNumber>
    </row>
    <row>
        <StackNumber>22</StackNumber>
        <BlockNumber>22456</BlockNumber>
        <DeliveryMode>TRANSIT</DeliveryMode>
        <LocationCode>MON</LocationCode>
        <BookVersion>03</BookVersion>
        <StoreNumber>1012</StoreNumber>
    </row>
    <row>
        <StackNumber>22</StackNumber>
        <BlockNumber>22456</BlockNumber>
        <DeliveryMode>RECVD</DeliveryMode>
        <LocationCode>MON</LocationCode>
        <BookVersion>02</BookVersion>
        <StoreNumber>1021</StoreNumber>
    </row>
</Output>
XSL (using saxon 9 parser) that I wrote:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" indent="yes"/>

    <xsl:key name="transitGroup" match="row" use="concat(StackNumber,BlockNumber,LocationCode)"/>

    <xsl:template match="/">
        <Output>
            <xsl:for-each select="//row[generate-id(.) = generate-id(key('transitGroup',concat(StackNumber,BlockNumber,LocationCode))[1])]">
                <xsl:variable name="BookVersion" select="key('transitGroup',concat(StackNumber,BlockNumber,LocationCode))/BookVersion"/>
                <xsl:if test="DeliveryMode = 'TRANSIT'">
                    <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>

                        <xsl:for-each select="$BookVersion">

                            <xsl:sort select="." data-type="number" order="descending"/>

                            <xsl:if test="position()=1">
                                <BookVersion>
                                    <xsl:value-of select="."/>
                                </BookVersion>
                            </xsl:if>
                        </xsl:for-each>
                    </row>
                </xsl:if>
            </xsl:for-each>
        </Output>
    </xsl:template>
</xsl:stylesheet>


I wrote  this above one but can't figure out to select correct store number based on greater value based element 'BookVersion' in each group.

example group must be printed like this .

<row>
<StackNumber>20</StackNumber>
<BlockNumber>61001</BlockNumber>
<LocationCode>MON</LocationCode>
<StoreNumber>1013</StoreNumber>
<BookVersion>02</BookVersion>
</row>

I'm getting wrong store number here for a particular selected group. I'm struck to proceed further here, I will appreciate if some body can lead me the way to write correct it in this XSL.
------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help