Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 September 24th, 2011, 05:48 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

That would require a completely different and much more complicated stylesheet. It would be reasonably to do in XSL 2.0 using xsl:for-each I think but much harder in XSLT 1.0 with grouping (search for Muenchian Method).
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old October 1st, 2011, 08:51 AM
Registered User
 
Join Date: Sep 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default change xslt processing order

Sam,

I have now got xsl which produces the output show below, but I want the output to be as shown in the expected out. Basically if I have multiple parcels in a consignment for a given delivery address I only want to out put the consignment and delivery address information for the group of parcels.

output :
JD0002210800004322
7255
044375530
JD0002210800004323
7256
044375531
JD0002210800004324
7257
044375532
JD0002210800004325
7257
044375532

Expected out:
JD0002210800004322
7255
044375530
JD0002210800004323
7256
044375531
JD0002210800004324
JD0002210800004325
7257
044375532

xsl I am using:

<?xml version="1.0" encoding="ISO-8859-1"?>

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

<xsl:output method='text'/>
<xsl:value-of select="current-date()"/>

<xsl:key name="parcelDetailsForAddress" match="DeliveryAddress"
use="following-sibling::Parcel[1]/@PARCEL_NO"/>
<xsl:key name="parcelDetailsForConsignment" match="Consignment"
use="following-sibling::Parcel[1]/@PARCEL_NO"/>

<xsl:variable name='newline'>
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="MR23030B">
<xsl:apply-templates select="Parcel"/>
</xsl:template>

<xsl:template match="Parcel">
<xsl:value-of select="@PARCEL_NO"/>
<xsl:value-of select="current-date()"/>
<xsl:value-of select="$newline"/>
<xsl:apply-templates select="key('parcelDetailsForAddress',@PARCEL_NO)"/>
<xsl:apply-templates select="key('parcelDetailsForConsignment',@PARCEL_ NO)"/>
</xsl:template>

<xsl:template match="DeliveryAddress">
<xsl:value-of select="@BRANCH_CODE"/>
<xsl:value-of select="$newline"/>
</xsl:template>

<xsl:template match="Consignment">
<xsl:value-of select="@ACNT_NO"/>
<xsl:value-of select="$newline"/>
</xsl:template>

</xsl:stylesheet>
 
Old October 5th, 2011, 01:00 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You haven't actually produced a sample input that produces either output above, but assuming the following input:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<MR23030B>
   <Header RECORD_TYPE="HD" METER_NO="10800" FILE_DATE="23/06/2011" RUN_NUMBER="000909"/>
   <SenderAddress RECORD_TYPE="AS" COUNTRY_CODE="GB" BRANCH_PREFIX="" BRANCH_CODE=""/>
   <Consignment RECORD_TYPE="CO" ACNT_NO="044375530" CONT_NO="9360964" COLL_PT="0001"/>
   <DeliveryAddress RECORD_TYPE="AD" COUNTRY_CODE="GB" BRANCH_PREFIX="07" BRANCH_CODE="7255"/>
   <Parcel RECORD_TYPE="PA" MANIFEST_NO="0000000000" PARCEL_NO="JD0002210800004322"/>
   <Consignment RECORD_TYPE="CO" ACNT_NO="044375531" CONT_NO="9360964" COLL_PT="0001"/>
   <DeliveryAddress RECORD_TYPE="AD" COUNTRY_CODE="GB" BRANCH_PREFIX="07" BRANCH_CODE="7256"/>
   <Parcel RECORD_TYPE="PA" MANIFEST_NO="0000000000" PARCEL_NO="JD0002210800004323"/>
   <Consignment RECORD_TYPE="CO" ACNT_NO="044375532" CONT_NO="9360964" COLL_PT="0001"/>
   <DeliveryAddress RECORD_TYPE="AD" COUNTRY_CODE="GB" BRANCH_PREFIX="07" BRANCH_CODE="7257"/>
   <Parcel RECORD_TYPE="PA" MANIFEST_NO="0000000000" PARCEL_NO="JD0002210800004324"/>
   <Consignment RECORD_TYPE="CO" ACNT_NO="044375532" CONT_NO="9360964" COLL_PT="0001"/>
   <DeliveryAddress RECORD_TYPE="AD" COUNTRY_CODE="GB" BRANCH_PREFIX="07" BRANCH_CODE="7257"/>
   <Parcel RECORD_TYPE="PA" MANIFEST_NO="0000000000" PARCEL_NO="JD0002210800004325"/>
   <TrailerRecord RECORD_TYPE="TR" NO_RECORDS="00000425"/>
</MR23030B>
This XSLT stylesheet produces the output required. The key is if you only want each consignment to appear once you must group on it first, then pull out the parcels with matching consignment values.

Code:
   <xsl:template match="MR23030B">
      <xsl:for-each-group select="Consignment" group-by="@ACNT_NO">	
 	       <xsl:for-each select="../Parcel[preceding-sibling::Consignment[1][@ACNT_NO = current()/@ACNT_NO]]">
 		         <xsl:value-of select="@PARCEL_NO"/>
            <xsl:text>
</xsl:text>
 		      </xsl:for-each>
 		      <xsl:value-of select="following-sibling::DeliveryAddress[1]/@BRANCH_CODE"/>
         <xsl:text>
</xsl:text>
 		      <xsl:value-of select="@ACNT_NO"/>
         <xsl:text>
</xsl:text>
      </xsl:for-each-group>
   </xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old October 9th, 2011, 01:53 PM
Registered User
 
Join Date: Sep 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default change xslt processing order

Hi Sam,

Thanks for your help that works just great.

Thanks again





Similar Threads
Thread Thread Starter Forum Replies Last Post
Order XML elements using XSLT imshriram XSLT 9 July 10th, 2011 10:56 AM
XSLT Processing shows just all the nodes (striped) tsmets XSLT 3 July 10th, 2010 05:42 AM
Array like processing (Xpath 1 / XSLT 1) akentanaka XSLT 1 July 2nd, 2008 02:22 AM
conditional xslt processing based on java array twilson997 XSLT 7 June 28th, 2006 07:32 AM
change order of an array automatically after add SauSaigon Beginning PHP 7 February 22nd, 2004 12:51 AM





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