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 July 9th, 2005, 08:56 AM
Registered User
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT Req

Hi

I have a requirement in XSLT, it is a bit lengthy. First of all let me give the source xml and the target output xml after transforming using XSLT and then explain the requirement.

Source XML

<?xml version="1.0" encoding="UTF-8"?>
<EDT20>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<CREDAT>20050708</CREDAT>
</EDI_DC40>
<E1EDT20 SEGMENT="1">
<Z1EDT20 SEGMENT="1">
<ZSHPCNTRY>US</ZSHPCNTRY>
<ZCURCOD>USD</ZCURCOD>
</Z1EDT20>
<Z1EDT20 SEGMENT="1">
<ZSHPCNTRY>US</ZSHPCNTRY>
<ZCURCOD>USD</ZCURCOD>
</Z1EDT20>
<E1EDL20 SEGMENT="1">
<BTGEW>6.200</BTGEW>
<GEWEI>LB</GEWEI>
<ANZPK>00001</ANZPK>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>WE</PARTNER_Q>
<PARTNER_ID>0004100357</PARTNER_ID>
<NAME1>COME CLEAN JANITORIAL</NAME1>
<COUNTRY1>US</COUNTRY1>
</E1ADRM1>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>OSO</PARTNER_Q>
<PARTNER_ID>0002</PARTNER_ID>
<NAME1>TENNANT</NAME1>
<COUNTRY1>US</COUNTRY1>
</E1ADRM1>
<E1EDL33>
<GRWCU>USD</GRWCU>
</E1EDL33>
<E1EDL47>
<SHIPACCT>560010</SHIPACCT>
<XSISRVC>03</XSISRVC>
<E1EDL48>
<XSIQUALF>BOOK1</XSIQUALF>
<VLABDATA>1234567</VLABDATA>
</E1EDL48>
<E1EDL48>
<XSIQUALF>PAGENR</XSIQUALF>
<VLABDATA>001</VLABDATA>
</E1EDL48>
<E1EDL48>
<XSIQUALF>ZCHARGTYPE</XSIQUALF>
<VLABDATA>PRE</VLABDATA>
</E1EDL48>
</E1EDL47>
<E1EDL37 SEGMENT="1">
<BRGEW>6.200</BRGEW>
<MEABM>INH</MEABM>
<E1EDL49>
<TRACKN>1Z5600100300083710</TRACKN>
</E1EDL49>
</E1EDL37>
</E1EDL20>
<E1EDL20 SEGMENT="1">
<BTGEW>6.200</BTGEW>
<GEWEI>LB</GEWEI>
<ANZPK>00001</ANZPK>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>WE</PARTNER_Q>
<PARTNER_ID>0004100357</PARTNER_ID>
<NAME1>COME CLEAN JANITORIAL</NAME1>
<COUNTRY1>US</COUNTRY1>
</E1ADRM1>
<E1EDL33>
<GRWCU>USD</GRWCU>
</E1EDL33>
<E1EDL47>
<SHIPACCT>560010</SHIPACCT>
<XSISRVC>03</XSISRVC>
<E1EDL48>
<XSIQUALF>BOOK1</XSIQUALF>
<VLABDATA>1234567</VLABDATA>
</E1EDL48>
<E1EDL48>
<XSIQUALF>PAGENR</XSIQUALF>
<VLABDATA>001</VLABDATA>
</E1EDL48>
<E1EDL48>
<XSIQUALF>ZCHARGTYPE</XSIQUALF>
<VLABDATA>PRE</VLABDATA>
</E1EDL48>
</E1EDL47>
<E1EDL37 SEGMENT="1">
<BRGEW>6.200</BRGEW>
<MEABM>INH</MEABM>
<E1EDL49>
<TRACKN>1Z5600100300083710</TRACKN>
</E1EDL49>
</E1EDL37>
</E1EDL20>
<E1EDL20 SEGMENT="1">
<BTGEW>6.200</BTGEW>
<GEWEI>LB</GEWEI>
<ANZPK>00001</ANZPK>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>WE</PARTNER_Q>
<PARTNER_ID>0004100350</PARTNER_ID>
<NAME1>INTERNATIONAL CLEANER</NAME1>
<COUNTRY1>US</COUNTRY1>
</E1ADRM1>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>ZY</PARTNER_Q>
<PARTNER_ID>UPS</PARTNER_ID>
<NAME1>UNITED PARCEL SERVICES</NAME1>
<COUNTRY1>US</COUNTRY1>
</E1ADRM1>
<E1EDL33>
<GRWCU>USD</GRWCU>
</E1EDL33>
<E1EDL47>
<SHIPACCT>560010</SHIPACCT>
<XSISRVC>02</XSISRVC>
<E1EDL48>
<XSIQUALF>BOOK1</XSIQUALF>
<VLABDATA>1234567</VLABDATA>
</E1EDL48>
<E1EDL48>
<XSIQUALF>PAGENR</XSIQUALF>
<VLABDATA>001</VLABDATA>
</E1EDL48>
<E1EDL48>
<XSIQUALF>ZCHARGTYPE</XSIQUALF>
<VLABDATA>PRE</VLABDATA>
</E1EDL48>
</E1EDL47>
<E1EDL37 SEGMENT="1">
<BRGEW>6.200</BRGEW>
<MEABM>INH</MEABM>
<E1EDL49>
<TRACKN>1Z5600100300083700</TRACKN>
</E1EDL49>
</E1EDL37>
</E1EDL20>
</E1EDT20>
</IDOC>
</EDT20>

XML After Transformation

<?xml version="1.0" encoding="UTF-8"?>
<Ship>
<PickupDate>20050708</PickupDate>
<Ship_BP>
<Identifier>*AA</Identifier>
<SenderShipperNumber>560010</SenderShipperNumber>
<ShipperCountry>US</ShipperCountry>
<BookNum>1234567</BookNum>
<PageNum>001</PageNum>
</Ship_BP>
<Ship_Info>
<Identifier>*BA</Identifier>
<ShipmentNumber>1Z5600100300083710</ShipmentNumber>
<PackageCount>00002</PackageCount>
<ShipmentActualWeight>12.400</ShipmentActualWeight>
<UOMWeight>LB</UOMWeight>
<UPSServiceType>03</UPSServiceType>
<ShipmentChgType>PRE</ShipmentChgType>
<UOMDim>INH</UOMDim>
<CurrencyCode>USD</CurrencyCode>
</Ship_Info>
<Ship_Info>
<Identifier>*BA</Identifier>
<ShipmentNumber>1Z5600100300083700</ShipmentNumber>
<PackageCount>00001</PackageCount>
<ShipmentActualWeight>6.200</ShipmentActualWeight>
<UOMWeight>LB</UOMWeight>
<UPSServiceType>02</UPSServiceType>
<ShipmentChgType>PRE</ShipmentChgType>
<UOMDim>INH</UOMDim>
<CurrencyCode>USD</CurrencyCode>
</Ship_Info>
<Address_Info>
<Identifier>*CA</Identifier>
<AddressQualifier>18</AddressQualifier>
<CompanyName>COME CLEAN JANITORIAL</CompanyName>
<Country>US</Country>
</Address_Info>
<Address_Info>
<Identifier>*CA</Identifier>
<AddressQualifier>18</AddressQualifier>
<CompanyName>INTERNATIONAL CLEANER</CompanyName>
<Country>US</Country>
</Address_Info>
<Address_Info>
<Identifier>*CA</Identifier>
<AddressQualifier>06</AddressQualifier>
<CompanyName>UNITED PARCEL SERVICE</CompanyName>
<Country>US</Country>
</Address_Info>
<Pkg_Info>
<Identifier>*PA</Identifier>
<PackageTrackingNumber>1Z5600100300083710</PackageTrackingNumber>
<PackageActualWeight>6.200</PackageActualWeight>
</Pkg_Info>
<Pkg_Info>
<Identifier>*PA</Identifier>
<PackageTrackingNumber>1Z5600100300083700</PackageTrackingNumber>
<PackageActualWeight>6.200</PackageActualWeight>
</Pkg_Info>
</Ship>

Now let me explain the scenario.
Under <Ship> node PickupDate maps to CREDAT.

Under <ShipBP> node,
Identifier is a constant '*AA'.
SenderShipperNumber will have the value of the first occurence of SHIPACCT, which is in the path /EDT20/IDOC/E1EDT20/E1EDL20/E1EDL47/SHIPACCT.
ShipperCountry maps to first value of ZSHPCNTRY, which is in the path /EDT20/IDOC/E1EDT20/Z1EDT20/ZSHPCNTRY.
BookNum has a small logic associated to it. It is first value of VLABDATA picked up from /EDT20/IDOC/E1EDT20/E1EDL20/E1EDL47/E1EDL48/VLABDATA with the check that XSIQUALF = 'BOOK1'.
PageNum also is similar to BookNum, except that the check is XSIQUALF = 'PAGENR'.

Now comes the next node <Ship_Info>. Identifier is a constant '*BA'. This is a bit complex. We see that the <Ship_Info> node comes thrice. The number of times the node is repeated is based on the following check. We should first identify the PARTNER_Q elements with value of 'WE'. PARTNER_Q is in the path, /EDT20/IDOC/E1EDT20/E1EDL20/E1ADRM1/PARTNER_Q. If the PARTNER_Q value is 'WE', then the value of 'AddressQualifier' would be '18',and also we should check for the PARTNER_ID value. If PARTNER_Q is 'WE' and PARTNER_ID value is the same then, we should basically aggregate the values of ANZPK (path is /EDT20/IDOC/E1EDT20/E1EDL20/ANZPK) for PackageCount, BRGEW (path is /EDT20/IDOC/E1EDT20/E1EDL20/E1EDL37/BRGEW) for ShipmentActualWeight.
In the above example, PARTNER_Q = 'WE' occurs 3 times. But out of the 3 times, the first 2 occurence has the same PARTNER_ID of 0004100357, so we club those 2 as a single occurence, and sum up corresponding ANZPK (00001 + 00001 = 00002) and BRGEW (6.200 + 6.200 = 12.400). Hence PackageCount will be '00002' and ShipmentActualWeight will be 12.400 the first time. Next for PARTNER_Q = 'WE' and PARTNER_ID =
0004100350, as it appears once, we just take the corresponding PackageCount and ShipmentActualWeight (00001 & 6.200 respectively). When PARTNER_Q = 'SP' then the AddressQualifier will have a value of '06'. Anyother PARTNER_Q value should not be considered at all. The other values such as UOMWeight (path is /EDT20/IDOC/E1EDT20/E1EDL20/GEWEI), UPSServiceType (path is /EDT20/IDOC/E1EDT20/E1EDL20/E1EDL47/XSISRVC),UOMDIM (path is /EDT20/IDOC/E1EDT20/E1EDL20/E1EDL37/MEABM), CurrencyCode (path is /EDT20/IDOC/E1EDT20/E1EDL20/E1EDL33/GRWCU). For ShipmentChgType (path is /EDT20/IDOC/E1EDT20/E1EDL20/E1EDL47/E1EDL48/VLABDATA) there is a condition check like XSIQUALF = 'ZCHARGTYPE'.

Next comes the final node <Pkg_Info>, here also the identifier is a constant. In this case this node occurs twice. This is based on PackageTrackingNumber i.e TRACKN (path is /EDT20/IDOC/E1EDT20/E1EDL20/E1EDL37/E1EDL49/TRACKN), if TRACKN is repeated ignore the duplicate, and take the corresponding PackageActualWeight i.e BRGEW (path is /EDT20/IDOC/E1EDT20/E1EDL20/E1EDL37/BRGEW).

I have tried my best to put forward the requirement, in case it is not clear please do ask me. Also remember the nodes are dynamic, so the number of nodes can change as per the source XML. I need a solution preferably in XSLT 1.0, if possible.

thanks
Sammy
 
Old July 10th, 2005, 02:52 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

A little bit of advice on posting questions.

Firstly, try to reduce the size of the files. No-one wants to wade through all this. It must be possible to extract the essence of the problem into a smaller example.

Secondly, show your efforts to solve the problem, even if they don't work. To help you solve this problem, I need to understand why you found it difficult, which I can't do without seeing your attempts to solve it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 11th, 2005, 01:54 AM
Registered User
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael

Point taken. But frankly speaking, i had actually reduced the file considerably and also just given a very small percentage of what my actual requirement was. If you go through the file, you will find out that most of the nodes are repeated.
But as you said i will further narrow down my requirement and ask you the part which i am finding harder than the rest. Basically i want to do a multiple grouping.
Let me make the target XML and Source XML smaller.
Source XML
<?xml version="1.0" encoding="UTF-8"?>
<Ship>
 <Address_Info>
  <AddressQualifier>WE</AddressQualifier>
  <Partner>121121</Partner>
  </Address_Info>
 <Address_Info>
  <AddressQualifier>WE</AddressQualifier>
  <Partner>121100</Partner>
  </Address_Info>
 <Address_Info>
  <AddressQualifier>ZY</AddressQualifier>
  <Partner>121122</Partner>
  </Address_Info>
 <Address_Info>
  <AddressQualifier>OSP</AddressQualifier>
  <Partner>121122</Partner>
  </Address_Info>
 <Address_Info>
  <AddressQualifier>WE</AddressQualifier>
  <Partner>121100</Partner>
  </Address_Info>
  </Ship>

Target XML after transformation

<?xml version="1.0" encoding="UTF-8"?>
<Ship>
 <Address_Info>
  <AddressQualifier>WE</AddressQualifier>
  <Partner>121121</Partner>
  </Address_Info>
 <Address_Info>
  <AddressQualifier>WE</AddressQualifier>
  <Partner>121100</Partner>
  </Address_Info>
</Ship>

I have to initially do a grouping by Partner, and then by AddressQualifier. I have to only identify AddressQualifier with value 'WE' and if it has same Partner group it together and show as output.
I tried the Muenchian method to do multiple grouping but i failed,
i tried something like this (a part of my coding...),

<xsl:key name="Partner" match="Ship/Address_Info" use="Partner"/>
<xsl:key name="AddressQualifier" match="Ship/Address_Info" use="AddressQualifier"/>

<xsl:template match="/">
<Ship>
<xsl:for-each select="Ship/Address_Info[generate-id(.) = generate-id(key('Partner', Partner)[1]) ]">
<xsl:variable name="group" select="key('AddressQualifier', AddressQualifier)"/>
<xsl:variable name="AQualifier">
<xsl:value-of select="AddressQualifier"/>
</xsl:variable>

<Address_Info>
<AddressQualifier>
<xsl:value-of select="$AQualifier"/>
</AddressQualifier>
</Address_Info>
</xsl:for-each>
</Ship>
</xsl:template>
</xsl:stylesheet>

Can you let me know the right way of doing multiple grouping.

thanks
Sammy



Quote:
quote:Originally posted by mhkay
 A little bit of advice on posting questions.

Firstly, try to reduce the size of the files. No-one wants to wade through all this. It must be possible to extract the essence of the problem into a smaller example.

Secondly, show your efforts to solve the problem, even if they don't work. To help you solve this problem, I need to understand why you found it difficult, which I can't do without seeing your attempts to solve it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 11th, 2005, 02:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's advice on multiple-level Muenchian grouping at

http://www.biglist.com/lists/xsl-lis.../msg00070.html



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Req for voice chat kesakiran ASP.NET 1.0 and 1.1 Professional 1 August 20th, 2007 12:14 PM
Req. To send the following files yadav4u Pro VB 6 0 April 20th, 2006 01:29 AM
Req. To send the following files yadav4u Pro VB 6 0 April 20th, 2006 01:27 AM
Two buttons, One page, + req~validators? developerz BOOK: ASP.NET Website Programming Problem-Design-Solution 4 October 1st, 2003 01:20 AM





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