At 2011-09-26 20:55 +0100, Navin Patel wrote:
I have been trying to solve this problem for a while but I haven't had
much luck.
This is easiest in XSLT 2.0, but thankfully your requirements are
simple enough that a solution in XSLT 1.0 is very straightforward.
I have attached the xml and the xslt file below, My desired output
for the given xml is:
Expected out:
JD0002210800004322
7255
044375530
JD0002210800004323
7256
044375531
JD0002210800004324
JD0002210800004325
7257
044375532
I don't understand why 4324 has no following and 4235 does, because
there are no records between the two. By what criteria does "4325"
have the records before "4324" following it?
Below I'm assuming the above output is wrong and that the 4325 is the
one that should have nothing following it.
but I am getting the following output:
Yes, because you are dealing with the sibling axes, which "don't know
how to stop".
I hope the key-based solution below helps ... it relies on looking up
those members that are keyed on their sibling parcel number. The
XSLT 2.0 solution would group the members using group-ending-with=.
. . . . . . . . Ken
t:\ftemp>type navin.xml
<?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"/>
<Parcel RECORD_TYPE="PA" MANIFEST_NO="0000000000"
PARCEL_NO="JD0002210800004325"/>
<TrailerRecord RECORD_TYPE="TR" NO_RECORDS="00000425"/>
</MR23030B>
t:\ftemp>xslt navin.xml navin.xsl
JD0002210800004322
7255
044375530
JD0002210800004323
7256
044375531
JD0002210800004324
7257
044375532
JD0002210800004325
t:\ftemp>type navin.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='text'/>
<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="$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>
t:\ftemp>
--
Contact us for world-wide XML consulting and instructor-led training
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--