kalyangkm
asked on
Identifying the same line item segments and consolidating the quantity
Hi Folks,
I have a scenario where in I need to check for the line items which are having the same PO number and if found need to sum up the quantities of both the line items and remove the other line item. Please check below of what I am trying to achieve
Input:
<Item 1>
<POline>PO1</POline>
<QUantity>2</QUantity>
</Item1>
<Item 2>
<POline>PO2</POline>
<QUantity>3</QUantity>
</Item2>
<Item 3>
<POline>PO1</POline>
<QUantity>5</QUantity>
</Item3>
Output:
<Item 1>
<POline>PO1</POline>
<QUantity>7</QUantity>
</Item 1>
<Item 2>
<POline>PO2</POline>
<QUantity>3</QUantity>
</Item 2>
So if you look at the output I am removing the Item3 segment and summing up the quantity corresponding to PO1 . Please help me develop this in Java
I have a scenario where in I need to check for the line items which are having the same PO number and if found need to sum up the quantities of both the line items and remove the other line item. Please check below of what I am trying to achieve
Input:
<Item 1>
<POline>PO1</POline>
<QUantity>2</QUantity>
</Item1>
<Item 2>
<POline>PO2</POline>
<QUantity>3</QUantity>
</Item2>
<Item 3>
<POline>PO1</POline>
<QUantity>5</QUantity>
</Item3>
Output:
<Item 1>
<POline>PO1</POline>
<QUantity>7</QUantity>
</Item 1>
<Item 2>
<POline>PO2</POline>
<QUantity>3</QUantity>
</Item 2>
So if you look at the output I am removing the Item3 segment and summing up the quantity corresponding to PO1 . Please help me develop this in Java
Please note I just need the segment creation java logic, don't need the DOM or SAX parsing logic because I have a middleware tool which generates the XML structure.Well then, you had better tell us a bit more about exactly how this data is represented IN JAVA rather than showing us the xml (it is essentially irrelevant), if you want us to help on the Java side of things.
ASKER
Actually this is graphical tool produces the same output as input. I can apply small inbuilt logics to the root nodes of the Item, but not this kind of complex logic. Anyways I was thinking if you can help me achieve this using XSLT mapping?
XSLT is probably the easier way to go.
However, can you tell me whether your XSLT processor is version 1 or version 2? Version 2 has some extra functionality that would make this easier. It can be done using either though.
However, can you tell me whether your XSLT processor is version 1 or version 2? Version 2 has some extra functionality that would make this easier. It can be done using either though.
Also, I assume that the XML examples given are made up by you and hand written, and not copy/paste from actual content. Because, firstly there is no root element and the "Item" element start/end tags don't match (and actually are invalid since you can't have a space in the element name). Can you provide the exact XML structure that you are dealing with as that will affect how the XSLT is written?
Here is an example using XSL 2.0.
Assuming that the input is the valid XML below...
Transforming it with this XSL...
Gives this output...
Assuming that the input is the valid XML below...
<?xml version="1.0" encoding="utf-8"?>
<root>
<Item1>
<POline>PO1</POline>
<QUantity>2</QUantity>
</Item1>
<Item2>
<POline>PO2</POline>
<QUantity>3</QUantity>
</Item2>
<Item3>
<POline>PO1</POline>
<QUantity>5</QUantity>
</Item3>
</root>
Transforming it with this XSL...
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/root">
<xsl:copy>
<xsl:for-each-group select="//POline/.." group-by="POline">
<xsl:element name="Item{position()}">
<POline><xsl:value-of select="current-grouping-key()" /></POline>
<QUantity><xsl:value-of select="sum(current-group()/QUantity)" /></QUantity>
</xsl:element>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Gives this output...
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Item1>
<POline>PO1</POline>
<QUantity>7</QUantity>
</Item1>
<Item2>
<POline>PO2</POline>
<QUantity>3</QUantity>
</Item2>
</root>
ASKER
Hi Mccarl,
Thank you, also I have an extension of the question, what if I have to group based on 2 fields one is poline which you have already shown and the other is invline as shown in the below code. If you want me to open a seperate question for this I can open
Input:
<Item 1>
<POline>PO1</POline>
<invline>INO1</invline>
<QUantity>2</QUantity>
</Item1>
<Item 2>
<POline>PO2</POline>
<invline>INO2</invline>
<QUantity>3</QUantity>
</Item2>
<Item 3>
<POline>PO1</POline>
<invline>INO1</invline>
<QUantity>5</QUantity>
</Item3>
Thank you, also I have an extension of the question, what if I have to group based on 2 fields one is poline which you have already shown and the other is invline as shown in the below code. If you want me to open a seperate question for this I can open
Input:
<Item 1>
<POline>PO1</POline>
<invline>INO1</invline>
<QUantity>2</QUantity>
</Item1>
<Item 2>
<POline>PO2</POline>
<invline>INO2</invline>
<QUantity>3</QUantity>
</Item2>
<Item 3>
<POline>PO1</POline>
<invline>INO1</invline>
<QUantity>5</QUantity>
</Item3>
ASKER
So the output should be
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Item1>
<POline>PO1</POline>
<invline>INO1</invline>
<QUantity>7</QUantity>
</Item1>
<Item2>
<POline>PO2</POline>
<invline>INO2</invline>
<QUantity>3</QUantity>
</Item2>
</root>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Item1>
<POline>PO1</POline>
<invline>INO1</invline>
<QUantity>7</QUantity>
</Item1>
<Item2>
<POline>PO2</POline>
<invline>INO2</invline>
<QUantity>3</QUantity>
</Item2>
</root>
It can be done, but i wont be able to mock up some code for you for a day or so, as I will be quite busy tomorrow. But if you wish to try this yourself, it involves concatenating the two element values in the 'group-by' clause and then you can't easily use current-grouping-key since it is the combined version, you have to extract the POline and Invline from the current-group elements. I forget the syntax of the top of my head but it might be something like current-group()[0]/POline
ASKER
Ok, I can try, but I am pretty new to this grouping concept. I will see if anyone else can answer in the meantime, if not please do it after you come back after a day or so
Ok, here is an example of grouping on multiple fields...
One thing to take note of is the group-by="" attribute. What I have done above is only suitable if your POline values and invline values are similar to your example. If however, the values in your real application were, for example, just numbers you would have a problem with input XML such as this...
When those two values are concat, in both case above, the result is "1234" and hence would be considered to be the same group.
If you believe that this may be an issue for you, there are two solutions. One is were you just concat another value between the two, such as group-by="concat(POline, '-', invline)". This assumes that the - can never appear in POline or invline values, otherwise you get the same issue. You can choose whatever character (or string of characters) such that they don't or would be unlikely to appear in the inputs.
If you want a solution that will work regardless of what characters might appear in the input, you need to do something a bit more complex. This nested for-each-group solution will do what you want, but is a bit more complex now because of the sequentially number Item elements that you want in the output. It would be a bit simpler if they weren't necessary.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/root">
<xsl:copy>
<xsl:for-each-group select="//POline/.." group-by="concat(POline, invline)">
<xsl:element name="Item{position()}">
<POline><xsl:value-of select="current-group()[1]/POline" /></POline>
<invline><xsl:value-of select="current-group()[1]/invline" /></invline>
<QUantity><xsl:value-of select="sum(current-group()/QUantity)" /></QUantity>
</xsl:element>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
One thing to take note of is the group-by="" attribute. What I have done above is only suitable if your POline values and invline values are similar to your example. If however, the values in your real application were, for example, just numbers you would have a problem with input XML such as this...
<?xml version="1.0" encoding="utf-8"?>
<root>
<Item1>
<POline>1</POline>
<invline>234</invline>
<QUantity>2</QUantity>
</Item1>
<Item2>
<POline>123</POline>
<invline>4</invline>
<QUantity>3</QUantity>
</Item2>
</root>
When those two values are concat, in both case above, the result is "1234" and hence would be considered to be the same group.
If you believe that this may be an issue for you, there are two solutions. One is were you just concat another value between the two, such as group-by="concat(POline, '-', invline)". This assumes that the - can never appear in POline or invline values, otherwise you get the same issue. You can choose whatever character (or string of characters) such that they don't or would be unlikely to appear in the inputs.
If you want a solution that will work regardless of what characters might appear in the input, you need to do something a bit more complex. This nested for-each-group solution will do what you want, but is a bit more complex now because of the sequentially number Item elements that you want in the output. It would be a bit simpler if they weren't necessary.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/root">
<xsl:copy>
<xsl:variable name="items">
<xsl:for-each-group select="//POline/.." group-by="POline">
<xsl:variable name="outerKey" select="current-grouping-key()" />
<xsl:for-each-group select="current-group()" group-by="invline">
<Item>
<POline><xsl:value-of select="$outerKey" /></POline>
<invline><xsl:value-of select="current-grouping-key()" /></invline>
<QUantity><xsl:value-of select="sum(current-group()/QUantity)" /></QUantity>
</Item>
</xsl:for-each-group>
</xsl:for-each-group>
</xsl:variable>
<xsl:for-each select="$items/Item">
<xsl:element name="Item{position()}">
<POline><xsl:value-of select="POline" /></POline>
<invline><xsl:value-of select="invline" /></invline>
<QUantity><xsl:value-of select="QUantity" /></QUantity>
</xsl:element>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
ASKER
Thank You Mccarl.As always you are very detail oriented. I don't have a special situation of numbers in the format you referred. Though it is numbers the values are big enough not to become duplicates. But the output is a bit different when I got the actual requirement. Please let me know if I have to create a separate question. The following is the format, actually it s a part of bigger
Input:
Output :
Currently I just have the following logic which doesn't implement the grouping, need to incorporate the grouping in the following. FYI, this is just a part of the XSLT mapping I have which also includes different other logic which is not shown.
Input:
<Item 1>
<POline>PO1</POline>
<invline>INO1</invline>
<QUantity>2</Quantity>
<INVOICE>INVOIC1</INVOICE>
<unit Price>2.5</Unit Price>
</Item1>
<Item 2>
<POline>PO2</POline>
<invline>INO2</invline>
<QUantity>3</QUantity>
<INVOICE>INVOIC2</INVOICE>
<unit Price>3.5</Unit Price>
</Item2>
<Item 3>
<POline>PO1</POline>
<invline>INO1</invline>
<QUantity>5</QUantity>
<INVOICE>INVOIC3</INVOICE>
<unit Price>2.5</Unit Price>
</Item3>
</root>
Output :
<E1EDP01>
<POSEX>INVOIC1</POSEX>
<MENGE>7</MENGE>
<E1EDP02>
<BELNR>PO1</BELNR>
<ZEILE>INO1</ZEILE>
</E1EDP02>
<E1EDP26>
<BETRG>17.5</BETRG> -------unit Price*QUantity
</E1EDP26>
</E1EDP01>
<E1EDP01>
<POSEX>INVOIC2</POSEX>
<MENGE>3</MENGE>
<E1EDP02>
<BELNR>PO2</BELNR>
<ZEILE>INO2</ZEILE>
</E1EDP02>
<E1EDP26>
<BETRG>10.5</BETRG> -------unit Price*QUantity
</E1EDP26>
</E1EDP01>
Currently I just have the following logic which doesn't implement the grouping, need to incorporate the grouping in the following. FYI, this is just a part of the XSLT mapping I have which also includes different other logic which is not shown.
<E1EDP01 SEGMENT="*">
<POSEX>
<xsl:value-of select="concat('00',normalize-space(root/INVOICE))"></xsl:value-of>
</POSEX>
<MENGE>
<xsl:value-of select="normalize-space(root/Quantity)"></xsl:value-of>
</MENGE>
<E1EDP02 SEGMENT="*">
<BELNR>
<xsl:value-of select="normalize-space(root/POline)"></xsl:value-of>
</BELNR>
<ZEILE>
<xsl:value-of select="concat('00',normalize-space(root/invline))"></xsl:value-of>
</ZEILE>
</E1EDP02>
<E1EDP26 SEGMENT="*">
<QUALF>002</QUALF>
<BETRG>
<xsl:value-of select="format-number(normalize-space(root/unit Price) * normalize-space(root/Quantity), '0.00')"></xsl:value-of>
</BETRG>
</E1EDP26>
</E1EDP01>
ASKER
FYI
the following tags are newly added to the input than what I had earlier
<INVOICE></INVOICE> -------------You can see this is unique for each segment
<unit Price></Unit Price> -------------this is same in case of similar items which needs to be grouped
the following tags are newly added to the input than what I had earlier
<INVOICE></INVOICE> -------------You can see this is unique for each segment
<unit Price></Unit Price> -------------this is same in case of similar items which needs to be grouped
ASKER
Hi McCarl,
Did you had time to check into my rek. Please let me know if you need more info or if you want me to close the current question and open a new one.
Did you had time to check into my rek. Please let me know if you need more info or if you want me to close the current question and open a new one.
ASKER
I am using XSLT 1.0 as my current middleware tool version SAP PI 7.11 supports only xslt 1.0. And I suppose that is the reason it says error in expression for the following line in my code
<xsl:value-of select="current-group()[1] /concat('0 0',normali ze-space(r oot/INVOIC E))" />
<xsl:value-of select="current-group()[1]
ASKER
Also I feel like I could be confusing you a lot. So if it helps I am putting the entire input xml and the XSLT that I currently have, please help me fix this.
Input XML
Current XSLT 1.0
My mapping for which I need this grouping goes under the following section, where in I am trying to consolidate the items by summing up the "SNItem/ShippingQuantity" for the items which have the same "SNItem/BuyersPONumber" and "SNItem/POLineNumber". and also trying to achieve the unit price/<BETRG> "FOB" for the summed up quantity
Input XML
<?xml version="1.0" encoding="UTF-8"?>
<ns0:INVOIC xmlns:ns0="http://XXXXXXX/gpi/INVOIC">
<Invoices>
<Monitoring>
<Tag>MSGH</Tag>
<Sender>3110</Sender>
<Receiver>4130</Receiver>
<MessageType>INVOIC</MessageType>
<MessageGroupNumber>7396</MessageGroupNumber>
<NumberOfRecord>4</NumberOfRecord>
<TransmissionDateTime>201409171319</TransmissionDateTime>
</Monitoring>
<Invoice>
<SNHeader>
<Tag>004</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<QuantityBeingShippedPiece>1</QuantityBeingShippedPiece>
<TotalAmountOfShipment>45.8</TotalAmountOfShipment>
<OnboardDate>20140916</OnboardDate>
<ShippingDate>20140916</ShippingDate>
<InvoiceDate>20140916</InvoiceDate>
<ModeOfTransportation>A1</ModeOfTransportation>
<PurposeOfAdvice>2</PurposeOfAdvice>
<TotalCases>1</TotalCases>
<TotalWeight>0</TotalWeight>
<SalesGroup>2001112A002A0</SalesGroup>
<ChargeFreeOfCharge>1</ChargeFreeOfCharge>
<Currency>EUR</Currency>
<ConsigneeID>0000000006</ConsigneeID>
<PaymentTerms>60 days net</PaymentTerms>
<DeclarationText1stLine>4500000675 weeklySAP</DeclarationText1stLine>
<InvoiceType>0</InvoiceType>
<PriceTerms>FOB</PriceTerms>
</SNHeader>
<SNHeader2>
<Tag>079</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
</SNHeader2>
<SNData>
<SNItem>
<Tag>061</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<InvoiceLine>001</InvoiceLine>
<SuppliersItemCodeInPO>00109</SuppliersItemCodeInPO>
<ShippingQuantity>3</ShippingQuantity>
<FOBUnitPrice>5</FOBUnitPrice>
<BuyersPONumber>4500000675</BuyersPONumber>
<POLineNumber>001</POLineNumber>
<CountryOfOrigin>DE</CountryOfOrigin>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<SuppliersItemCodeInSO>00109</SuppliersItemCodeInSO>
</SNItem>
<SNDetail>
<Tag>005</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<ShippingQuantity>1</ShippingQuantity>
<NetWeight>0</NetWeight>
<PackagingLevelCoded>3</PackagingLevelCoded>
<PackingStyle>0</PackingStyle>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<InvoiceLine>001</InvoiceLine>
</SNDetail>
</SNData>
<SNData>
<SNItem>
<Tag>061</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<InvoiceLine>001</InvoiceLine>
<SuppliersItemCodeInPO>00109</SuppliersItemCodeInPO>
<ShippingQuantity>1</ShippingQuantity>
<FOBUnitPrice>45.8</FOBUnitPrice>
<BuyersPONumber>4500000676</BuyersPONumber>
<POLineNumber>002</POLineNumber>
<CountryOfOrigin>DE</CountryOfOrigin>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<SuppliersItemCodeInSO>00109</SuppliersItemCodeInSO>
</SNItem>
<SNDetail>
<Tag>005</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<ShippingQuantity>1</ShippingQuantity>
<NetWeight>0</NetWeight>
<PackagingLevelCoded>3</PackagingLevelCoded>
<PackingStyle>0</PackingStyle>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<InvoiceLine>001</InvoiceLine>
</SNDetail>
</SNData>
<SNData>
<SNItem>
<Tag>061</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<InvoiceLine>001</InvoiceLine>
<SuppliersItemCodeInPO>00109</SuppliersItemCodeInPO>
<ShippingQuantity>2</ShippingQuantity>
<FOBUnitPrice>5</FOBUnitPrice>
<BuyersPONumber>4500000675</BuyersPONumber>
<POLineNumber>001</POLineNumber>
<CountryOfOrigin>DE</CountryOfOrigin>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<SuppliersItemCodeInSO>00109</SuppliersItemCodeInSO>
</SNItem>
<SNDetail>
<Tag>005</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<ShippingQuantity>1</ShippingQuantity>
<NetWeight>0</NetWeight>
<PackagingLevelCoded>3</PackagingLevelCoded>
<PackingStyle>0</PackingStyle>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<InvoiceLine>001</InvoiceLine>
</SNDetail>
</SNData>
<SNData>
<SNItem>
<Tag>061</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<InvoiceLine>001</InvoiceLine>
<SuppliersItemCodeInPO>00109</SuppliersItemCodeInPO>
<ShippingQuantity>1</ShippingQuantity>
<FOBUnitPrice>45.8</FOBUnitPrice>
<BuyersPONumber>4500000676</BuyersPONumber>
<POLineNumber>002</POLineNumber>
<CountryOfOrigin>DE</CountryOfOrigin>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<SuppliersItemCodeInSO>00109</SuppliersItemCodeInSO>
</SNItem>
<SNDetail>
<Tag>005</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<ShippingQuantity>1</ShippingQuantity>
<NetWeight>0</NetWeight>
<PackagingLevelCoded>3</PackagingLevelCoded>
<PackingStyle>0</PackingStyle>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<InvoiceLine>001</InvoiceLine>
</SNDetail>
</SNData>
</Invoice>
<Invoice>
<SNHeader>
<Tag>004</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<QuantityBeingShippedPiece>1</QuantityBeingShippedPiece>
<TotalAmountOfShipment>45.8</TotalAmountOfShipment>
<OnboardDate>20140916</OnboardDate>
<ShippingDate>20140916</ShippingDate>
<InvoiceDate>20140916</InvoiceDate>
<ModeOfTransportation>A1</ModeOfTransportation>
<PurposeOfAdvice>2</PurposeOfAdvice>
<TotalCases>1</TotalCases>
<TotalWeight>0</TotalWeight>
<SalesGroup>2001112A002A0</SalesGroup>
<ChargeFreeOfCharge>1</ChargeFreeOfCharge>
<Currency>EUR</Currency>
<ConsigneeID>0000000006</ConsigneeID>
<PaymentTerms>60 days net</PaymentTerms>
<DeclarationText1stLine>4500000675 weeklySAP</DeclarationText1stLine>
<InvoiceType>0</InvoiceType>
<PriceTerms>FOB</PriceTerms>
</SNHeader>
<SNHeader2>
<Tag>079</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
</SNHeader2>
<SNData>
<SNItem>
<Tag>061</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<InvoiceLine>001</InvoiceLine>
<SuppliersItemCodeInPO>00109</SuppliersItemCodeInPO>
<ShippingQuantity>3</ShippingQuantity>
<FOBUnitPrice>5</FOBUnitPrice>
<BuyersPONumber>4500000685</BuyersPONumber>
<POLineNumber>001</POLineNumber>
<CountryOfOrigin>DE</CountryOfOrigin>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<SuppliersItemCodeInSO>00109</SuppliersItemCodeInSO>
</SNItem>
<SNDetail>
<Tag>005</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<ShippingQuantity>1</ShippingQuantity>
<NetWeight>0</NetWeight>
<PackagingLevelCoded>3</PackagingLevelCoded>
<PackingStyle>0</PackingStyle>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<InvoiceLine>001</InvoiceLine>
</SNDetail>
</SNData>
<SNData>
<SNItem>
<Tag>061</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<InvoiceLine>001</InvoiceLine>
<SuppliersItemCodeInPO>00109</SuppliersItemCodeInPO>
<ShippingQuantity>1</ShippingQuantity>
<FOBUnitPrice>45.8</FOBUnitPrice>
<BuyersPONumber>4500000676</BuyersPONumber>
<POLineNumber>002</POLineNumber>
<CountryOfOrigin>DE</CountryOfOrigin>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<SuppliersItemCodeInSO>00109</SuppliersItemCodeInSO>
</SNItem>
<SNDetail>
<Tag>005</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<ShippingQuantity>1</ShippingQuantity>
<NetWeight>0</NetWeight>
<PackagingLevelCoded>3</PackagingLevelCoded>
<PackingStyle>0</PackingStyle>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<InvoiceLine>001</InvoiceLine>
</SNDetail>
</SNData>
<SNData>
<SNItem>
<Tag>061</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<InvoiceLine>001</InvoiceLine>
<SuppliersItemCodeInPO>00109</SuppliersItemCodeInPO>
<ShippingQuantity>2</ShippingQuantity>
<FOBUnitPrice>5</FOBUnitPrice>
<BuyersPONumber>4500000675</BuyersPONumber>
<POLineNumber>001</POLineNumber>
<CountryOfOrigin>DE</CountryOfOrigin>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<SuppliersItemCodeInSO>00109</SuppliersItemCodeInSO>
</SNItem>
<SNDetail>
<Tag>005</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<ShippingQuantity>1</ShippingQuantity>
<NetWeight>0</NetWeight>
<PackagingLevelCoded>3</PackagingLevelCoded>
<PackingStyle>0</PackingStyle>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<InvoiceLine>001</InvoiceLine>
</SNDetail>
</SNData>
<SNData>
<SNItem>
<Tag>061</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<InvoiceLine>001</InvoiceLine>
<SuppliersItemCodeInPO>00109</SuppliersItemCodeInPO>
<ShippingQuantity>1</ShippingQuantity>
<FOBUnitPrice>45.8</FOBUnitPrice>
<BuyersPONumber>4500000676</BuyersPONumber>
<POLineNumber>002</POLineNumber>
<CountryOfOrigin>DE</CountryOfOrigin>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<SuppliersItemCodeInSO>00109</SuppliersItemCodeInSO>
</SNItem>
<SNDetail>
<Tag>005</Tag>
<DataID>1</DataID>
<Seller>3110</Seller>
<Buyer>4130</Buyer>
<ReportedDateTime>20140916233000</ReportedDateTime>
<InvoiceNumber>10212014</InvoiceNumber>
<SellersInternalControlNumber>195549002000</SellersInternalControlNumber>
<ShippingQuantity>1</ShippingQuantity>
<NetWeight>0</NetWeight>
<PackagingLevelCoded>3</PackagingLevelCoded>
<PackingStyle>0</PackingStyle>
<MeasureForShippingQuantity>C62</MeasureForShippingQuantity>
<InvoiceLine>001</InvoiceLine>
</SNDetail>
</SNData>
</Invoice>
</Invoices>
</ns0:INVOIC>
Current XSLT 1.0
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://olympus.co.jp/gpi/INVOIC"
exclude-result-prefixes="ns0" xmlns:propertyUtil="com.utils.PropertyUtil">
<xsl:template match="/">
<xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>
<INVOIC02>
<xsl:for-each select="ns0:INVOIC/Invoices/Invoice">
<IDOC BEGIN="1">
<EDI_DC40>
<TABNAM>EDI_DC40</TABNAM>
<MANDT></MANDT>
<DOCNUM></DOCNUM>
<DOCREL></DOCREL>
<STATUS></STATUS>
<DIRECT></DIRECT>
<OUTMOD>
</OUTMOD>
<IDOCTYP>INVOIC02</IDOCTYP>
<MESTYP>INVOIC</MESTYP>
<STD>E</STD>
<STDVRS>D 98B</STDVRS>
<STDMES>INVOIC</STDMES>
<SNDPOR></SNDPOR>
<SNDPRT>LI</SNDPRT>
<SNDPFC>LF</SNDPFC>
<SNDPRN>
<xsl:choose>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'QX1'">
<xsl:value-of select="'0000104444'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'DX1'">
<xsl:value-of select="'0000103056'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'PX1'">
<xsl:value-of select="'0000104474'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'QX1'">
<xsl:value-of select="'0000104465'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'DX1'">
<xsl:value-of select="'0000103076'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'PX1'">
<xsl:value-of select="'0000104495'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</SNDPRN>
<RCVPOR></RCVPOR>
<RCVPRT></RCVPRT>
<RCVPRN></RCVPRN>
<CREDAT></CREDAT>
<CRETIM></CRETIM>
</EDI_DC40>
<E1EDK01 SEGMENT="*">
<CURCY>
<xsl:value-of select="normalize-space(SNHeader/Currency)"></xsl:value-of>
</CURCY>
<BSART>RE</BSART>
<BELNR>
<xsl:value-of select="normalize-space(SNHeader/InvoiceNumber)"></xsl:value-of>
</BELNR>
</E1EDK01>
<E1EDKA1 SEGMENT="*">
<PARVW>RE</PARVW>
<PARTN>
<xsl:choose>
<xsl:when test="normalize-space (SNHeader/Buyer) = '4130'">
<xsl:value-of select="'2001'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space (SNHeader/Buyer) = '4101'">
<xsl:value-of select="'2002'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</PARTN>
</E1EDKA1>
<E1EDKA1 SEGMENT="*">
<PARVW>LF</PARVW>
<PARTN>
<xsl:choose>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'QX1'">
<xsl:value-of select="'0000104444'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'DX1'">
<xsl:value-of select="'0000103056'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'PX1'">
<xsl:value-of select="'0000104474'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'QX1'">
<xsl:value-of select="'0000104465'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'DX1'">
<xsl:value-of select="'0000103076'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'PX1'">
<xsl:value-of select="'0000104495'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</PARTN>
</E1EDKA1>
<E1EDK02 SEGMENT="*">
<QUALF>009</QUALF>
<BELNR>
<xsl:value-of select="normalize-space(SNHeader/InvoiceNumber)"></xsl:value-of>
</BELNR>
</E1EDK02>
<E1EDK03 SEGMENT="*">
<IDDAT>012</IDDAT>
<DATUM>
<xsl:value-of select="normalize-space(SNHeader/InvoiceDate)"></xsl:value-of>
</DATUM>
</E1EDK03>
<E1EDK03 SEGMENT="*">
<IDDAT>024</IDDAT>
<DATUM>
<xsl:value-of select="normalize-space(SNHeader/OnboardDate)"></xsl:value-of>
</DATUM>
</E1EDK03>
<E1EDK04 SEGMENT="*">
<MWSKZ>VAT</MWSKZ>
</E1EDK04>
<xsl:for-each select="SNData">
<E1EDP01 SEGMENT="*">
<POSEX>
<xsl:value-of select="concat('00',normalize-space(SNItem/InvoiceLine))"></xsl:value-of>
</POSEX>
<MENGE>
<xsl:value-of select="normalize-space(SNItem/ShippingQuantity)"></xsl:value-of>
</MENGE>
<MENEE>
<xsl:choose>
<xsl:when
test="normalize-space(SNItem/MeasureForShippingQuantity) = 'C62'">
<xsl:value-of select="'EA'"></xsl:value-of>
</xsl:when>
<xsl:when
test="normalize-space(SNItem/MeasureForShippingQuantity) = 'DZN'">
<xsl:value-of select="'DZ'"></xsl:value-of>
</xsl:when>
<xsl:when
test="normalize-space(SNItem/MeasureForShippingQuantity) = 'st'">
<xsl:value-of select="'EA'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</MENEE>
<E1EDP02 SEGMENT="*">
<QUALF>001</QUALF>
<BELNR>
<xsl:value-of select="normalize-space(SNItem/BuyersPONumber)"></xsl:value-of>
</BELNR>
<ZEILE>
<xsl:value-of select="concat('00',normalize-space(SNItem/POLineNumber))"></xsl:value-of>
</ZEILE>
</E1EDP02>
<E1EDP26 SEGMENT="*">
<QUALF>002</QUALF>
<BETRG>
<xsl:value-of select="format-number(normalize-space(SNItem/FOBUnitPrice) * normalize-space(SNItem/ShippingQuantity), '0.00')"></xsl:value-of>
</BETRG>
</E1EDP26>
<E1EDP04 SEGMENT="*">
<MWSKZ>VAT</MWSKZ>
</E1EDP04>
</E1EDP01>
</xsl:for-each>
<E1EDS01 SEGMENT="*">
<SUMID>010</SUMID>
<SUMME>
<xsl:value-of select="normalize-space(SNHeader/TotalAmountOfShipment)"></xsl:value-of>
</SUMME>
</E1EDS01>
</IDOC>
</xsl:for-each>
</INVOIC02>
</xsl:template>
</xsl:stylesheet>
My mapping for which I need this grouping goes under the following section, where in I am trying to consolidate the items by summing up the "SNItem/ShippingQuantity" for the items which have the same "SNItem/BuyersPONumber" and "SNItem/POLineNumber". and also trying to achieve the unit price/<BETRG> "FOB" for the summed up quantity
<xsl:for-each select="SNData">
<E1EDP01 SEGMENT="*">
<POSEX>
<xsl:value-of select="concat('00',normalize-space(SNItem/InvoiceLine))"></xsl:value-of>
</POSEX>
<MENGE>
<xsl:value-of select="normalize-space(SNItem/ShippingQuantity)"></xsl:value-of>
</MENGE>
<MENEE>
<xsl:choose>
<xsl:when
test="normalize-space(SNItem/MeasureForShippingQuantity) = 'C62'">
<xsl:value-of select="'EA'"></xsl:value-of>
</xsl:when>
<xsl:when
test="normalize-space(SNItem/MeasureForShippingQuantity) = 'DZN'">
<xsl:value-of select="'DZ'"></xsl:value-of>
</xsl:when>
<xsl:when
test="normalize-space(SNItem/MeasureForShippingQuantity) = 'st'">
<xsl:value-of select="'EA'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</MENEE>
<E1EDP02 SEGMENT="*">
<QUALF>001</QUALF>
<BELNR>
<xsl:value-of select="normalize-space(SNItem/BuyersPONumber)"></xsl:value-of>
</BELNR>
<ZEILE>
<xsl:value-of select="concat('00',normalize-space(SNItem/POLineNumber))"></xsl:value-of>
</ZEILE>
</E1EDP02>
<E1EDP26 SEGMENT="*">
<QUALF>002</QUALF>
<BETRG>
<xsl:value-of select="format-number(normalize-space(SNItem/FOBUnitPrice) * normalize-space(SNItem/ShippingQuantity), '0.00')"></xsl:value-of>
</BETRG>
</E1EDP26>
<E1EDP04 SEGMENT="*">
<MWSKZ>VAT</MWSKZ>
</E1EDP04>
</E1EDP01>
</xsl:for-each>
I was just in the middle of typing up a comment, saying how better to state your problem (including providing more representative inputs/outputs, etc). What you have now done looks much better, so I will have a look at that and get back to you.
And yes, XSLT 1.0 would be half the reason for the error that you are getting, also that expression would be invalid anyway even in 2.0.
Give me a little while to look at a XSLT 1.0 compatible grouping solution...
And yes, XSLT 1.0 would be half the reason for the error that you are getting, also that expression would be invalid anyway even in 2.0.
Give me a little while to look at a XSLT 1.0 compatible grouping solution...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Looks like the sysntax error, I am getting the following error at the expression " <xsl:for-each select="$items/item[not(ke y = preceding-sibling::item/ke y)]">"
"To use a result tree fragment in a path expression, either use exsl:node-set() or specify version='1.1'"
"To use a result tree fragment in a path expression, either use exsl:node-set() or specify version='1.1'"
ASKER
Hi Mccarl,
to fix the result tree fragment in a path expression issue, I have modified the syntax to use exsl:node-set(), not sure if this is right. but atleast it bypaseed the error that I was getting was able to execute the xslt only having to find that the <E1EDP01> segments are missing in the output. Please check into this if the code needs any modification.
XSLT
output xml
to fix the result tree fragment in a path expression issue, I have modified the syntax to use exsl:node-set(), not sure if this is right. but atleast it bypaseed the error that I was getting was able to execute the xslt only having to find that the <E1EDP01> segments are missing in the output. Please check into this if the code needs any modification.
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://olympus.co.jp/gpi/INVOIC"
exclude-result-prefixes="ns0" xmlns:propertyUtil="com.utils.PropertyUtil" xmlns:exsl="http://exslt.org/common">
<xsl:template match="/">
<xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>
<INVOIC02>
<xsl:for-each select="ns0:INVOIC/Invoices/Invoice">
<IDOC BEGIN="1">
<EDI_DC40>
<TABNAM>EDI_DC40</TABNAM>
<MANDT></MANDT>
<DOCNUM></DOCNUM>
<DOCREL></DOCREL>
<STATUS></STATUS>
<DIRECT></DIRECT>
<OUTMOD>
</OUTMOD>
<IDOCTYP>INVOIC02</IDOCTYP>
<MESTYP>INVOIC</MESTYP>
<STD>E</STD>
<STDVRS>D 98B</STDVRS>
<STDMES>INVOIC</STDMES>
<SNDPOR></SNDPOR>
<SNDPRT>LI</SNDPRT>
<SNDPFC>LF</SNDPFC>
<SNDPRN>
<xsl:choose>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'QX1'">
<xsl:value-of select="'0000104444'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'DX1'">
<xsl:value-of select="'0000103056'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'PX1'">
<xsl:value-of select="'0000104474'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'QX1'">
<xsl:value-of select="'0000104465'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'DX1'">
<xsl:value-of select="'0000103076'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'PX1'">
<xsl:value-of select="'0000104495'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</SNDPRN>
<RCVPOR></RCVPOR>
<RCVPRT></RCVPRT>
<RCVPRN></RCVPRN>
<CREDAT></CREDAT>
<CRETIM></CRETIM>
</EDI_DC40>
<E1EDK01 SEGMENT="*">
<CURCY>
<xsl:value-of select="normalize-space(SNHeader/Currency)"></xsl:value-of>
</CURCY>
<BSART>RE</BSART>
<BELNR>
<xsl:value-of select="normalize-space(SNHeader/InvoiceNumber)"></xsl:value-of>
</BELNR>
</E1EDK01>
<E1EDKA1 SEGMENT="*">
<PARVW>RE</PARVW>
<PARTN>
<xsl:choose>
<xsl:when test="normalize-space (SNHeader/Buyer) = '4130'">
<xsl:value-of select="'2001'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space (SNHeader/Buyer) = '4101'">
<xsl:value-of select="'2002'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</PARTN>
</E1EDKA1>
<E1EDKA1 SEGMENT="*">
<PARVW>LF</PARVW>
<PARTN>
<xsl:choose>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'QX1'">
<xsl:value-of select="'0000104444'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'DX1'">
<xsl:value-of select="'0000103056'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '1032' and normalize-space($SystemName) = 'PX1'">
<xsl:value-of select="'0000104474'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'QX1'">
<xsl:value-of select="'0000104465'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'DX1'">
<xsl:value-of select="'0000103076'"></xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space(SNHeader/Seller) = '3110' and normalize-space($SystemName) = 'PX1'">
<xsl:value-of select="'0000104495'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</PARTN>
</E1EDKA1>
<E1EDK02 SEGMENT="*">
<QUALF>009</QUALF>
<BELNR>
<xsl:value-of select="normalize-space(SNHeader/InvoiceNumber)"></xsl:value-of>
</BELNR>
</E1EDK02>
<E1EDK03 SEGMENT="*">
<IDDAT>012</IDDAT>
<DATUM>
<xsl:value-of select="normalize-space(SNHeader/InvoiceDate)"></xsl:value-of>
</DATUM>
</E1EDK03>
<E1EDK03 SEGMENT="*">
<IDDAT>024</IDDAT>
<DATUM>
<xsl:value-of select="normalize-space(SNHeader/OnboardDate)"></xsl:value-of>
</DATUM>
</E1EDK03>
<E1EDK04 SEGMENT="*">
<MWSKZ>VAT</MWSKZ>
</E1EDK04>
<xsl:variable name="items">
<xsl:for-each select="SNDATA">
<item>
<key><xsl:value-of select="concat(SNItem/BuyersPONumber, '-', SNItem/POLineNumber)" /></key>
<poNumber><xsl:value-of select="normalize-space(SNItem/BuyersPONumber)" /></poNumber>
<lineNumber><xsl:value-of select="concat('00',normalize-space(SNItem/POLineNumber))" /></lineNumber>
<invoiceLine><xsl:value-of select="concat('00',normalize-space(SNItem/InvoiceLine))" /></invoiceLine>
<quantity><xsl:value-of select="normalize-space(SNItem/ShippingQuantity)" /></quantity>
<measure><xsl:value-of select="normalize-space(SNItem/MeasureForShippingQuantity)" /></measure>
<price><xsl:value-of select="normalize-space(SNItem/FOBUnitPrice) * normalize-space(SNItem/ShippingQuantity)" /></price>
</item>
</xsl:for-each>
</xsl:variable>
<!--<xsl:for-each select="SNData"> -->
<!-- <xsl:for-each select="$items/item[not(key = preceding-sibling::item/key)]"> -->
<xsl:for-each select="exsl:node-set($items)/item[not(key = preceding-sibling::item/key)]">
<E1EDP01 SEGMENT="*">
<POSEX>
<xsl:value-of select="invoiceLine"></xsl:value-of>
</POSEX>
<MENGE>
<!-- <xsl:value-of select="normalize-space(SNItem/ShippingQuantity)"></xsl:value-of> -->
<xsl:value-of select="sum(exsl:node-set($items)/item[key = current()/key]/quantity)"></xsl:value-of>
</MENGE>
<MENEE>
<xsl:choose>
<xsl:when
test="measure = 'C62'">
<xsl:value-of select="'EA'"></xsl:value-of>
</xsl:when>
<xsl:when
test="measure = 'DZN'">
<xsl:value-of select="'DZ'"></xsl:value-of>
</xsl:when>
<xsl:when
test="measure = 'st'">
<xsl:value-of select="'EA'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</MENEE>
<E1EDP02 SEGMENT="*">
<QUALF>001</QUALF>
<BELNR>
<xsl:value-of select="poNumber"></xsl:value-of>
</BELNR>
<ZEILE>
<xsl:value-of select="lineNumber"></xsl:value-of>
</ZEILE>
</E1EDP02>
<E1EDP26 SEGMENT="*">
<QUALF>002</QUALF>
<BETRG>
<xsl:value-of select="sum(exsl:node-set($items)/item[key = current()/key]/price)"></xsl:value-of>
</BETRG>
</E1EDP26>
<E1EDP04 SEGMENT="*">
<MWSKZ>VAT</MWSKZ>
</E1EDP04>
</E1EDP01>
</xsl:for-each>
<E1EDS01 SEGMENT="*">
<SUMID>010</SUMID>
<SUMME>
<xsl:value-of select="normalize-space(SNHeader/TotalAmountOfShipment)"></xsl:value-of>
</SUMME>
</E1EDS01>
</IDOC>
</xsl:for-each>
</INVOIC02>
</xsl:template>
</xsl:stylesheet>
output xml
<?xml version="1.0" encoding="UTF-8"?>
<INVOIC02 xmlns:exsl="http://exslt.org/common" xmlns:propertyUtil="com.utils.PropertyUtil">
<IDOC BEGIN="1">
<EDI_DC40>
<TABNAM>EDI_DC40</TABNAM>
<MANDT/>
<DOCNUM/>
<DOCREL/>
<STATUS/>
<DIRECT/>
<OUTMOD/>
<IDOCTYP>INVOIC02</IDOCTYP>
<MESTYP>INVOIC</MESTYP>
<STD>E</STD>
<STDVRS>D 98B</STDVRS>
<STDMES>INVOIC</STDMES>
<SNDPOR/>
<SNDPRT>LI</SNDPRT>
<SNDPFC>LF</SNDPFC>
<SNDPRN>0000103056</SNDPRN>
<RCVPOR/>
<RCVPRT/>
<RCVPRN/>
<CREDAT/>
<CRETIM/>
</EDI_DC40>
<E1EDK01 SEGMENT="*">
<CURCY>USD</CURCY>
<BSART>RE</BSART>
<BELNR>99001523</BELNR>
</E1EDK01>
<E1EDKA1 SEGMENT="*">
<PARVW>RE</PARVW>
<PARTN>2002</PARTN>
</E1EDKA1>
<E1EDKA1 SEGMENT="*">
<PARVW>LF</PARVW>
<PARTN>0000103056</PARTN>
</E1EDKA1>
<E1EDK02 SEGMENT="*">
<QUALF>009</QUALF>
<BELNR>99001523</BELNR>
</E1EDK02>
<E1EDK03 SEGMENT="*">
<IDDAT>012</IDDAT>
<DATUM>20140425</DATUM>
</E1EDK03>
<E1EDK03 SEGMENT="*">
<IDDAT>024</IDDAT>
<DATUM>20140425</DATUM>
</E1EDK03>
<E1EDK04 SEGMENT="*">
<MWSKZ>VAT</MWSKZ>
</E1EDK04>
<E1EDS01 SEGMENT="*">
<SUMID>010</SUMID>
<SUMME>0.3</SUMME>
</E1EDS01>
</IDOC>
<IDOC BEGIN="1">
<EDI_DC40>
<TABNAM>EDI_DC40</TABNAM>
<MANDT/>
<DOCNUM/>
<DOCREL/>
<STATUS/>
<DIRECT/>
<OUTMOD/>
<IDOCTYP>INVOIC02</IDOCTYP>
<MESTYP>INVOIC</MESTYP>
<STD>E</STD>
<STDVRS>D 98B</STDVRS>
<STDMES>INVOIC</STDMES>
<SNDPOR/>
<SNDPRT>LI</SNDPRT>
<SNDPFC>LF</SNDPFC>
<SNDPRN>0000103056</SNDPRN>
<RCVPOR/>
<RCVPRT/>
<RCVPRN/>
<CREDAT/>
<CRETIM/>
</EDI_DC40>
<E1EDK01 SEGMENT="*">
<CURCY>USD</CURCY>
<BSART>RE</BSART>
<BELNR>99001498</BELNR>
</E1EDK01>
<E1EDKA1 SEGMENT="*">
<PARVW>RE</PARVW>
<PARTN>2002</PARTN>
</E1EDKA1>
<E1EDKA1 SEGMENT="*">
<PARVW>LF</PARVW>
<PARTN>0000103056</PARTN>
</E1EDKA1>
<E1EDK02 SEGMENT="*">
<QUALF>009</QUALF>
<BELNR>99001498</BELNR>
</E1EDK02>
<E1EDK03 SEGMENT="*">
<IDDAT>012</IDDAT>
<DATUM>20140425</DATUM>
</E1EDK03>
<E1EDK03 SEGMENT="*">
<IDDAT>024</IDDAT>
<DATUM>20140425</DATUM>
</E1EDK03>
<E1EDK04 SEGMENT="*">
<MWSKZ>VAT</MWSKZ>
</E1EDK04>
<E1EDS01 SEGMENT="*">
<SUMID>010</SUMID>
<SUMME>14.6</SUMME>
</E1EDS01>
</IDOC>
<IDOC BEGIN="1">
<EDI_DC40>
<TABNAM>EDI_DC40</TABNAM>
<MANDT/>
<DOCNUM/>
<DOCREL/>
<STATUS/>
<DIRECT/>
<OUTMOD/>
<IDOCTYP>INVOIC02</IDOCTYP>
<MESTYP>INVOIC</MESTYP>
<STD>E</STD>
<STDVRS>D 98B</STDVRS>
<STDMES>INVOIC</STDMES>
<SNDPOR/>
<SNDPRT>LI</SNDPRT>
<SNDPFC>LF</SNDPFC>
<SNDPRN>0000103056</SNDPRN>
<RCVPOR/>
<RCVPRT/>
<RCVPRN/>
<CREDAT/>
<CRETIM/>
</EDI_DC40>
<E1EDK01 SEGMENT="*">
<CURCY>USD</CURCY>
<BSART>RE</BSART>
<BELNR>99001499</BELNR>
</E1EDK01>
<E1EDKA1 SEGMENT="*">
<PARVW>RE</PARVW>
<PARTN>2002</PARTN>
</E1EDKA1>
<E1EDKA1 SEGMENT="*">
<PARVW>LF</PARVW>
<PARTN>0000103056</PARTN>
</E1EDKA1>
<E1EDK02 SEGMENT="*">
<QUALF>009</QUALF>
<BELNR>99001499</BELNR>
</E1EDK02>
<E1EDK03 SEGMENT="*">
<IDDAT>012</IDDAT>
<DATUM>20140425</DATUM>
</E1EDK03>
<E1EDK03 SEGMENT="*">
<IDDAT>024</IDDAT>
<DATUM>20140425</DATUM>
</E1EDK03>
<E1EDK04 SEGMENT="*">
<MWSKZ>VAT</MWSKZ>
</E1EDK04>
<E1EDS01 SEGMENT="*">
<SUMID>010</SUMID>
<SUMME>32.9</SUMME>
</E1EDS01>
</IDOC>
</INVOIC02>
I have modified the syntax to use exsl:node-set(), not sure if this is right.Using extension functions can be tricky and dependant on the processor being used, but if you aren't getting any errors, hopefully it is right.
At least one reason for not getting any E1EDP01 elements in the output is that you have changed line 130 (of the XSLT that you have posted just above) from SNData to SNDATA, and since XPath expressions that select elements are case-sensitive it isn't finding any SNData elements to process.
ASKER
Thank You. As usual you are awesome!
You're welcome! Glad to help :)
ASKER