Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2006, 10:15 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Not reading last record group.

I have a problem that is driving me nuts. I have a fairly flat input file like this:

<Records>
    <Record>
        <Field1>8150000606</Field1>
        <Field2>00010</Field2>
        <Field9>20060623</Field9>
    </Record>
    <Record>
        <Field1>8150000606</Field1>
        <Field2>00020</Field2>
        <Field9>20060623</Field9>
    </Record>
    <Record>
        <Field1>8150000606</Field1>
        <Field2>00060</Field2>
        <Field3>JP02</Field3>
        <Field9>20060624</Field9>
    </Record>
    <Record>
        <Field1>8150000606</Field1>
        <Field2>00070</Field2>
        <Field9>20060624</Field9>
    </Record>
    <Record>
        <Field1>8150000607</Field1>
        <Field2>00010</Field2>
        <Field9>20060623</Field9>
    </Record>
    <Record>
        <Field1>8150000607</Field1>
        <Field2>00020</Field2>
        <Field9>20060624</Field9>
    </Record>
</Records>

Field1=PONumber, Field2=LineNumber, Field3=PostingDate

The requirement is to create a new PO whenever the PONumber or Posting Date changes, so that I should have four PO's created.

1 PO for 8150000606/20060623 with lines 00010/00020, 1 PO for 8150000606/20060624 with lines 00060/00070, 1 PO for 8150000607/20060623 with line 00010 and finally 1 po for 8150000607/20060624 with line 00020.

I am checking preceding-sibling::Record/Field1 or preceding-sibling::Record/Field9 to test the level breaks. All works fine, except the last <Record> never gets processed.

I am using xmlSpy debugger to test this, and Xalan when it gets into production.

Am I missing something fundamental?

XSL follows:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:template match="/Records">
        <PurchaseOrder>
            <xsl:for-each select="Record[not(Field1 = preceding-sibling::Record/Field1) or not(Field9 = preceding-sibling::Record/Field9)]">
                <xsl:sort order="ascending" select="Field1"/>
                <xsl:sort order="ascending" select="Field9"/>
                <PurchaseOrderHeader>
                    <PurchaseOrderNumber>
                        <xsl:value-of select="Field1"/>
                    </PurchaseOrderNumber>
                    <POCreateDate>
                        <xsl:value-of select="Field9"/>
                    </POCreateDate>
                    <xsl:variable name="Test" select="Field9"/>
                    <xsl:variable name="Test1" select="Field1"/>
                    <xsl:for-each select="/Records/Record[Field1 = $Test1 and Field9 = $Test]">
                        <xsl:call-template name="GetRecords">
                        </xsl:call-template>
                    </xsl:for-each>
                </PurchaseOrderHeader>
            </xsl:for-each>
        </PurchaseOrder>
    </xsl:template>
    <xsl:template name="GetRecords">
        <ProductLineItem>
            <LineNumber>
                <xsl:value-of select="normalize-space(Field2)"/>
            </LineNumber>
        </ProductLineItem>
    </xsl:template>
</xsl:stylesheet>

 
Old July 12th, 2006, 10:28 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The expression

Field1 = preceding-sibling::Record/Field1

compares with *all* the preceding siblings and returns true if any one matches. You want

Field1 = preceding-sibling::Record[1]/Field1

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 13th, 2006, 02:35 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael - Superb. works a treat, and shows a distinct lacking in my interpretation. Cheers!





Similar Threads
Thread Thread Starter Forum Replies Last Post
One Record From Each Group - Query rstelma SQL Server 2000 7 January 3rd, 2008 12:08 AM
SQL query retrieving last record and group by snowy SQL Language 2 December 13th, 2006 01:59 PM
Selecting top record of a group by clause lic023 Access 7 June 7th, 2006 11:25 AM
SQL Query - picking latest record and group by markw SQL Language 2 April 6th, 2005 03:54 AM
Supress record when running total in group meets c ldejesuspr Crystal Reports 1 July 28th, 2004 11:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.