Re: [xsl] change xslt processing order

Subject: Re: [xsl] change xslt processing order
From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 4 Oct 2011 18:22:13 -0400
I got your expected results by running your original data and
transform from your very first message modified only by the addition
of the <xsl:if> I described, as follows:

  <xsl:template match="Parcel">
    <xsl:value-of select="@PARCEL_NO"/>
    <xsl:value-of select="$newline"/>
    <xsl:if test="not(following-sibling::*[1][self::Parcel])">
      <xsl:apply-templates select="preceding-sibling::DeliveryAddress[1]"/>
      <xsl:apply-templates select="preceding-sibling::Consignment[1]"/>
    </xsl:if>
  </xsl:template>

On Tue, Oct 4, 2011 at 3:16 PM, Navin Patel <navin98@xxxxxxxxx> wrote:
> Brandon,
>
> Thanks for your suggestion, but I do want to output the
> DeliveryAddress and Consignment after a Parcel even if one parcel
> follows another its just that I want output the DeliveryAddress and
> Consignment after the last parcel in a group of parcels i.e.

If a Parcel, "4", is immediately followed by another Parcel, "5", then
Parcel "4" isn't the last in the group, right?

The above test breaks down like this:
1. Select all following sibling nodes that are elements.
(following-sibling::*)
2. Of these, select just the first in document order. ([1])
3. Discard this unless it is a Parcel. ([self::Parcel])
4. Return true if there are no nodes left. (not())

-Brandon :)


> Expected out:
> JD0002210800004322
> 7255
> 044375530
> JD0002210800004323
> 7256
> 044375531
> JD0002210800004324
> JD0002210800004325
> 7257
> 044375532
>
> With the suggestion below I don't get any output for the
> DeliveryAddress and Consignment for the last two parcels in the XML.
>
> The "test" on the <xsl:if> would be
> "not(following-sibling::*[1][self::Parcel])".  This would output the
> DeliveryAddress and Consignment after a Parcel only if it was not
> immediately followed by another Parcel.
>
> JD0002210800004322
> 7255
>  044375530
> JD0002210800004323
> 7256
> 044375531
> JD0002210800004324
> JD0002210800004325
>
> Thanks
>
> Navin

Current Thread