Hi People,
I want to transform this XML document:
<?xml version="1.0" encoding="UTF-8"?>
<notification-history-response xmlns=" serial-number="ca8575fb-fa68-4657-bd67-9c65be145a84">
<notifications>
<order-state-change-notification serial-number="372522188722936-00006-1">
<timestamp>2009-02-17T11:21:12.977Z</timestamp>
<google-order-number>372522188722936</google-order-number>
<new-fulfillment-order-state>NEW</new-fulfillment-order-state>
<new-financial-order-state>CHARGEABLE</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>REVIEWING</previous-financial-order-state>
</order-state-change-notification>
<order-state-change-notification serial-number="372522188722936-00007-1">
<timestamp>2009-02-25T14:05:58.385Z</timestamp>
<google-order-number>372522188722936</google-order-number>
<new-fulfillment-order-state>WILL_NOT_DELIVER</new-fulfillment-order-state>
<new-financial-order-state>CANCELLED</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>CHARGEABLE</previous-financial-order-state>
</order-state-change-notification>
<order-state-change-notification serial-number="635864704530878-00005-1">
<timestamp>2009-02-17T16:50:15.598Z</timestamp>
<google-order-number>635864704530878</google-order-number>
<new-fulfillment-order-state>NEW</new-fulfillment-order-state>
<new-financial-order-state>CHARGEABLE</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>REVIEWING</previous-financial-order-state>
</order-state-change-notification>
<order-state-change-notification serial-number="635864704530878-00006-1">
<timestamp>2009-02-25T14:05:19.990Z</timestamp>
<google-order-number>635864704530878</google-order-number>
<new-fulfillment-order-state>WILL_NOT_DELIVER</new-fulfillment-order-state>
<new-financial-order-state>CANCELLED</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>CHARGEABLE</previous-financial-order-state>
</order-state-change-notification>
<order-state-change-notification serial-number="745942158683282-00004-1">
<timestamp>2009-02-23T17:05:31.658Z</timestamp>
<google-order-number>745942158683282</google-order-number>
<new-fulfillment-order-state>WILL_NOT_DELIVER</new-fulfillment-order-state>
<new-financial-order-state>CANCELLED</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>REVIEWING</previous-financial-order-state>
</order-state-change-notification>
</notification-history-response>
..... into THIS XML document:
<?xml version="1.0" encoding="UTF-8"?>
<ROWSET>
<ROW>
<GOOGLE_ORDER_NO>372522188722936</GOOGLE_ORDER_NO>
<ORDER_STATE>CANCELLED</ORDER_STATE>
<DATE_UPDATED>2009-02-25T14:05:58.385Z</DATE_UPDATED>
</ROW>
<ROW>
<GOOGLE_ORDER_NO>635864704530878</GOOGLE_ORDER_NO>
<ORDER_STATE>CANCELLED</ORDER_STATE>
<DATE_UPDATED>2009-02-25T14:05:19.990Z</DATE_UPDATED>
</ROW>
<ROW>
<GOOGLE_ORDER_NO>745942158683282</GOOGLE_ORDER_NO>
<ORDER_STATE>CANCELLED</ORDER_STATE>
<DATE_UPDATED>2009-02-23T17:05:31.658Z</DATE_UPDATED>
</ROW>
</ROWSET>
Basically, I want to ensure that each "google-order-number" element is sorted in ascending order of "timestamp", and then take the latest "new-financial-order-state" and "timestamp" element values for each Google Order Number, and transfer them to ORDER_STATE and DATE_UPDATED in the new XML document.
Essentially, I'm trying to group the output on "google-order-number", and am only interested in the "new-financial-order-state" associated with the latest "timestamp".
I came up with the follwing XSLT to do the sorting:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=" version="1.0" xmlns:gc="<xslutput method="xml"/>
<xsl:template match="gc:notification-history-response/gc:notifications">
<xsl:for-each select="gcrder-state-change-notification" order-by="+gc:google-order-number; +gc:timestamp">
<ROWSET>
<!-- Unfortunately, after spending the last 3 hours buried in books and on the web,
I've not been able to figure this next bit out.
-->
</ROWSET>
</xsl:template>
</xsl:stylesheet>
Unfortunately, try as I might, I've not been able to figure out what should go where the comments are. I've developed a reasonable number of basic XSL stylesheets, but this is a tad more involved.
Any help or suggestions would be appreciated.
Cheers.
James
I want to transform this XML document:
<?xml version="1.0" encoding="UTF-8"?>
<notification-history-response xmlns=" serial-number="ca8575fb-fa68-4657-bd67-9c65be145a84">
<notifications>
<order-state-change-notification serial-number="372522188722936-00006-1">
<timestamp>2009-02-17T11:21:12.977Z</timestamp>
<google-order-number>372522188722936</google-order-number>
<new-fulfillment-order-state>NEW</new-fulfillment-order-state>
<new-financial-order-state>CHARGEABLE</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>REVIEWING</previous-financial-order-state>
</order-state-change-notification>
<order-state-change-notification serial-number="372522188722936-00007-1">
<timestamp>2009-02-25T14:05:58.385Z</timestamp>
<google-order-number>372522188722936</google-order-number>
<new-fulfillment-order-state>WILL_NOT_DELIVER</new-fulfillment-order-state>
<new-financial-order-state>CANCELLED</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>CHARGEABLE</previous-financial-order-state>
</order-state-change-notification>
<order-state-change-notification serial-number="635864704530878-00005-1">
<timestamp>2009-02-17T16:50:15.598Z</timestamp>
<google-order-number>635864704530878</google-order-number>
<new-fulfillment-order-state>NEW</new-fulfillment-order-state>
<new-financial-order-state>CHARGEABLE</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>REVIEWING</previous-financial-order-state>
</order-state-change-notification>
<order-state-change-notification serial-number="635864704530878-00006-1">
<timestamp>2009-02-25T14:05:19.990Z</timestamp>
<google-order-number>635864704530878</google-order-number>
<new-fulfillment-order-state>WILL_NOT_DELIVER</new-fulfillment-order-state>
<new-financial-order-state>CANCELLED</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>CHARGEABLE</previous-financial-order-state>
</order-state-change-notification>
<order-state-change-notification serial-number="745942158683282-00004-1">
<timestamp>2009-02-23T17:05:31.658Z</timestamp>
<google-order-number>745942158683282</google-order-number>
<new-fulfillment-order-state>WILL_NOT_DELIVER</new-fulfillment-order-state>
<new-financial-order-state>CANCELLED</new-financial-order-state>
<previous-fulfillment-order-state>NEW</previous-fulfillment-order-state>
<previous-financial-order-state>REVIEWING</previous-financial-order-state>
</order-state-change-notification>
</notification-history-response>
..... into THIS XML document:
<?xml version="1.0" encoding="UTF-8"?>
<ROWSET>
<ROW>
<GOOGLE_ORDER_NO>372522188722936</GOOGLE_ORDER_NO>
<ORDER_STATE>CANCELLED</ORDER_STATE>
<DATE_UPDATED>2009-02-25T14:05:58.385Z</DATE_UPDATED>
</ROW>
<ROW>
<GOOGLE_ORDER_NO>635864704530878</GOOGLE_ORDER_NO>
<ORDER_STATE>CANCELLED</ORDER_STATE>
<DATE_UPDATED>2009-02-25T14:05:19.990Z</DATE_UPDATED>
</ROW>
<ROW>
<GOOGLE_ORDER_NO>745942158683282</GOOGLE_ORDER_NO>
<ORDER_STATE>CANCELLED</ORDER_STATE>
<DATE_UPDATED>2009-02-23T17:05:31.658Z</DATE_UPDATED>
</ROW>
</ROWSET>
Basically, I want to ensure that each "google-order-number" element is sorted in ascending order of "timestamp", and then take the latest "new-financial-order-state" and "timestamp" element values for each Google Order Number, and transfer them to ORDER_STATE and DATE_UPDATED in the new XML document.
Essentially, I'm trying to group the output on "google-order-number", and am only interested in the "new-financial-order-state" associated with the latest "timestamp".
I came up with the follwing XSLT to do the sorting:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=" version="1.0" xmlns:gc="<xslutput method="xml"/>
<xsl:template match="gc:notification-history-response/gc:notifications">
<xsl:for-each select="gcrder-state-change-notification" order-by="+gc:google-order-number; +gc:timestamp">
<ROWSET>
<!-- Unfortunately, after spending the last 3 hours buried in books and on the web,
I've not been able to figure this next bit out.
-->
</ROWSET>
</xsl:template>
</xsl:stylesheet>
Unfortunately, try as I might, I've not been able to figure out what should go where the comments are. I've developed a reasonable number of basic XSL stylesheets, but this is a tad more involved.
Any help or suggestions would be appreciated.
Cheers.
James