Jump to content

Change Processing Order


fredf

Recommended Posts

Hi,I have this xml file, in my XSLT file I want to process <Parcel .../> element first then the <DeliveryAdress ../> and then the <Consignment .../> element.I would be very grateful if someone could suggest a solution please.Thanks in advance.<xml version="1.0" ?><MR23030B><Header RECORD_TYPE="HD" METER_NO="10800" FILE_DATE="23/06/2011" RUN_NUMBER="000909"NO_RECORDS="00000425" LAYOUT_VERSION="000002" GAZ_VERSION="000107" /><SenderAddress RECORD_TYPE="AS" COUNTRY_CODE="GB" BRANCH_PREFIX="" BRANCH_CODE=""EUROEXPRESS_ACNT="" /><Consignment RECORD_TYPE="CO" ACNT_NO="044375530" CONT_NO="9360964" COLL_PT="0001"AND ACCESSORIES" /><DeliveryAddress RECORD_TYPE="AD" COUNTRY_CODE="GB" BRANCH_PREFIX="07"CNCT_FAX="" CNCT_VAT="" CNCT_E_EMAIL="" ACNT_IN_PARTNER="" EUROEXPRESS_ACNT="" /><Parcel RECORD_TYPE="PA" MANIFEST_NO="0000000000" NOTE_NO="001"PARCEL_CONTENT="CARD AND ACCESSORIES" /><TrailerRecord RECORD_TYPE="TR" NO_RECORDS="00000425" /></MR23030B>

Link to comment
Share on other sites

Well with XSLT 2.0 you can simply write one apply-templates listing the elements in the order you want them processed in:

<xsl:template match="MR23030B">   <xsl:apply-templates select="Parcel, DeliveryAddress, Consignment"/></xsl:template><!-- now put templates here to transform the elements as needed -->

With XSLT 1.0 you will need to write three apply-templates e.g.

<xsl:template match="MR23030B">   <xsl:apply-templates select="Parcel"/>  <xsl:apply-templates select="DeliveryAddress"/>  <xsl:apply-templates select="Consignment"/></xsl:template><!-- now put templates here to transform the elements as needed -->

Link to comment
Share on other sites

Hi Martin, I have tried your suggestion as shown below, but the only thing with that is that I get all the parcels first, then the Address and then the consignment info.as show 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"?>JD0002210800004322JD0002210800004323 JD0002210800004324 7255 7256 7257 0443755...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>

Link to comment
Share on other sites

Well the sample you showed in your first post has exactly one Parcel element, one DeliveryAddress element, not several. If your real data has more than one of each of those elements you will need to show us a sample, in particular we need to know whether there are also several MR23030B. Otherwise it is difficult to suggest code processing those elements in a particular order.

Link to comment
Share on other sites

Sorry Martin I have attached the XML data below. <?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>

Link to comment
Share on other sites

Hi Martin,I am very grateful for your suggestions. I tried your suggestion of using the code below but I get the output show below but I want the output be asshown in the expected output format:<xsl:template match="MR23030B"> <xsl:apply-templates select="Parcel"/> <xsl:apply-templates select="DeliveryAddress"/> <xsl:apply-templates select="Consignment"/></xsl:template>output:JD0002210800004322 JD0002210800004323 JD0002210800004324 JD0002210800004325 7255 7256 7257 044375530 044375531 044375532 expected output :JD0002210800004322 7255 044375530 JD0002210800004323 7256 044375531 JD0002210800004324 JD0002210800004325 7257 044375532:

Link to comment
Share on other sites

  • 2 weeks later...

Martin. I now xslt which produces as show in the output, however I want the out put as shown in the expected output, do you know how I could change the xslt to get the expected output. Thanks in advance output:JD00022108000043227255044375530JD00022108000043237256044375531JD00022108000043247257044375532JD00022108000043257257044375532 Expected out:JD00022108000043227255044375530JD00022108000043237256044375531JD0002210800004324JD00022108000043257257044375532<?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)"/>- Hide quoted text -</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>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...