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 19th, 2011, 03:21 PM
Registered User
 
Join Date: Sep 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default change xslt processing order

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="mr23030b.xsl"?>
<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"/>
<TrailerRecord RECORD_TYPE="TR" NO_RECORDS="00000425"/>
</MR23030B>



I have the xml as shown above but with XSL style sheet I have attached below, I get all the parcels being processed first, then the Address and then the consignment info.as shown below, but I want the data to come out as parcel,Address Consignment,parcel,Address Consignment,parcel,Address consignment etc.

<?xml version="1.0" encoding="UTF-16"?>
JD0002210800004322
JD0002210800004323
JD0002210800004324
7255
7256
7257
0443
755...
i.e
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="MR23030B">
<xsl:apply-templates select="Parcel"/>
<xsl:apply-templates select="DeliveryAddress"/>
<xsl:apply-templates select="Consignment"/>
</xsl:template>

<xsl:variable name='newline'>
<xsl:text> </xsl:text>
</xsl:variable>

<xsl:template match="Parcel">
<xsl:value-of select="@PARCEL_NO"/>
<xsl:value-of select="$newline"/>
</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:value-of select="$newline"/>
</xsl:template>
</xsl:stylesheet>
 
Old September 19th, 2011, 05:27 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If you want them to come out in the original document order then include them all in a single xsl:apply-templates instruction:

Code:
<xsl:apply-templates select="Parce | DeliveryAddressl | Consignment"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

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

Hi Sam,

I don't want them to come out in the document order(Consignment,DeliveryAddress,Parcel). I want them to come out in this order (Parcel, DeliveryAddress, Consignment)

I was wondering if I need to use the preceding-sibling, following-sibling functionality?

Thanks
 
Old September 20th, 2011, 05:05 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Assuming you want to show the parcel, then the preceding delivery address, and then the preceding Consignment then yes, you'd use preceding-sibling, something like this:

Code:
<xsl:template match="MR23030B">
<xsl:apply-templates select="Parcel"/>
</xsl:template>

<xsl:template match="Parcel">
<xsl:value-of select="@PARCEL_NO"/>
<xsl:apply-templates select="preceding-sibling::DeliveryAddress[1]"/>
<xsl:apply-templates select="preceding-sibling::Consignment[1]"/>
</xsl:template>
The DeliveryAddress and Consignment templates would not change.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old September 22nd, 2011, 03:18 PM
Registered User
 
Join Date: Sep 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default change xslt processing order

Hi Sam,

I tried your suggestion as shown below but I still get all the parcels coming out first i.e.

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource 'wmh:C:\Documents and Settings\Navin.HOME-AX30XLSW34\My...

<?xml version="1.0" encoding="UTF-16"?>JD0002210800004322 JD0002210800004323 JD0002210800004324 JD0002210800004325
-----...




<?xml version = "1.0" encoding = "utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="MR23030B">
<xsl:apply-templates select="Parcel"/>
</xsl:template>

<xsl:template match="Parcel">
<xsl:value-of select="@PARCEL_NO"/>
<xsl:apply-templates select="preceding-sibling::DeliveryAddress[1]"/>
<xsl:apply-templates select="preceding-sibling::Consignment[1]"/>
</xsl:template>
</xsl:stylesheet>
 
Old September 22nd, 2011, 07:45 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You have not included the templates for DeliveryAddress and Consignment. I did say they would be the same.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old September 23rd, 2011, 01:36 PM
Registered User
 
Join Date: Sep 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default change xslt processing order

Hi Sam,

Is this what you meant :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="MR23030B">
<xsl:apply-templates select="Parcel"/>
<xsl:apply-templates select="DeliveryAddress"/>
<xsl:apply-templates select="Consignment"/>
</xsl:template>

<xsl:template match="Parcel">
<xsl:value-of select="@PARCEL_NO"/>
<xsl:apply-templates select="preceding-sibling::DeliveryAddress[1]"/>
<xsl:apply-templates select="preceding-sibling::Consignment[1]"/>
</xsl:template>
</xsl:stylesheet>

I still get the same output i.e.

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource 'wmh:C:\Documents and Settings\Navin.HOME-AX30XLSW34\My...

<?xml version="1.0" encoding="UTF-16"?>JD0002210800004322JD0002210800004323JD0002210 800004324JD0002210800004325
-----...
 
Old September 23rd, 2011, 01:47 PM
Registered User
 
Join Date: Sep 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default change xslt processing order

Sam,

I have also tried the code below, but I still get the same result as above, can you spot whats wrong with the code ?

Thanks

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="MR23030B">
<xsl:apply-templates select="Parcel"/>
<xsl:apply-templates select="preceding-sibling::DeliveryAddress[1]"/>
<xsl:apply-templates select="preceding-sibling::Consignment[1]"/>
</xsl:template>

<xsl:template match="Parcel">
<xsl:value-of select="@PARCEL_NO"/>
</xsl:template>
<xsl:template match="DeliveryAddress">
<xsl:value-of select="@BRANCH_CODE"/>
</xsl:template>
<xsl:template match="Consignment">
<xsl:value-of select="@ACNT_NO"/>
</xsl:template>
</xsl:stylesheet>
 
Old September 23rd, 2011, 04:08 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

No, I meant this:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

<xsl:template match="Parcel">
<xsl:value-of select="@PARCEL_NO"/>
<xsl:apply-templates select="preceding-sibling::DeliveryAddress[1]"/>
<xsl:apply-templates select="preceding-sibling::Consignment[1]"/>
</xsl:template>

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

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

</xsl:stylesheet>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old September 24th, 2011, 10:56 AM
Registered User
 
Join Date: Sep 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default change xslt processing order

Hi Sam,

Thanks , that works, the only other thing as you say is that when I have more than one parcel against the the delivery address and consignment I am going to have the delelivery address and the consignment information repeated. Do you know a way stopping that so I get the expected output shown below.

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

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





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.