I am trying to join multiple order-lines into one order. But I can't get my system to do it, so I hope you can help with an XSLT that can do it in the file....
Old file:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <TOTHEM> <HEADER>
<TYPE>INSDES</TYPE>
<SENDER>me</SENDER>
<RECEIVER>Them</RECEIVER>
<DOCUMENT_REFERENCE>
<ID>5655850111</ID>
<TIMESTAMP>2022-11-30 11:42:52</TIMESTAMP>
</DOCUMENT_REFERENCE> </HEADER> <ORDER ID="TO-20402">
<EXTERNAL_DOCUMENT_NO></EXTERNAL_DOCUMENT_NO>
<REFERENCE>TO-20402</REFERENCE>
<ORDER_DATE>30-11-2022</ORDER_DATE>
<DELIVERY_DATE>30-11-2022</DELIVERY_DATE>
<PICK_COMMENT></PICK_COMMENT>
<CARRIER></CARRIER>
<SHIP>
<SHIP_ID>me</SHIP_ID>
<SHIP_NAME>me</SHIP_NAME>
<SHIP_NAME2></SHIP_NAME2>
<SHIP_ADDRESS>here</SHIP_ADDRESS>
<SHIP_ADDRESS2></SHIP_ADDRESS2>
<SHIP_POSTCODE>8600</SHIP_POSTCODE>
<SHIP_CITY>Silkeborg</SHIP_CITY>
<SHIP_COUNTRY_CODE>DK</SHIP_COUNTRY_CODE>
<SHIP_ATT></SHIP_ATT>
<SHIP_COMMENT></SHIP_COMMENT>
<SHIP_MAIL></SHIP_MAIL>
<SHIP_PHONE_NO></SHIP_PHONE_NO>
<SHIP_SMS></SHIP_SMS>
</SHIP>
<RECEIVE>
<RECEIVE_ID></RECEIVE_ID>
<RECEIVE_NAME></RECEIVE_NAME>
<RECEIVE_ADDRESS></RECEIVE_ADDRESS>
<RECEIVE_ADDERSS2></RECEIVE_ADDERSS2>
<RECEIVE_POSTCODE></RECEIVE_POSTCODE>
<RECEIVE_CITY></RECEIVE_CITY>
<RECEIVE_COUNTRY_CODE></RECEIVE_COUNTRY_CODE>
<RECEIVE_CONTACT></RECEIVE_CONTACT>
</RECEIVE>
<ORDER_CUSTOM_FIELDS>
<ORDER_CUSTOM_FIELD1></ORDER_CUSTOM_FIELD1>
...
<ORDER_CUSTOM_FIELD5></ORDER_CUSTOM_FIELD5>
</ORDER_CUSTOM_FIELDS>
<LINES>
<LINE ID="4054009">
<ARTICLE_NO>260250104</ARTICLE_NO>
<ARTICLE_EAN>5707644776470</ARTICLE_EAN>
<ARTICLE_DESCRIPTION></ARTICLE_DESCRIPTION>
<ARTICLE_DESCRIPTION2></ARTICLE_DESCRIPTION2>
<ARTICLE_ID>102406528</ARTICLE_ID>
<QUANTITY>150</QUANTITY>
<UNIT_OF_MEASURE>Pcs</UNIT_OF_MEASURE>
<LOT_NO></LOT_NO>
<EXPIRATION_DATE></EXPIRATION_DATE>
<LINE_CUSTOM_FIELDS>
<LINE_CUSTOM_FIELD1></LINE_CUSTOM_FIELD1>
...
<LINE_CUSTOM_FIELD5></LINE_CUSTOM_FIELD5>
</LINE_CUSTOM_FIELDS>
</LINE>
</LINES> </ORDER> <ORDER ID="TO-20403">
<EXTERNAL_DOCUMENT_NO></EXTERNAL_DOCUMENT_NO>
<REFERENCE>TO-20403</REFERENCE>
<ORDER_DATE>30-11-2022</ORDER_DATE>
<DELIVERY_DATE>30-11-2022</DELIVERY_DATE>
<PICK_COMMENT></PICK_COMMENT>
<CARRIER></CARRIER>
<LINES>
<LINE ID="4054010">
<ARTICLE_NO>164800001</ARTICLE_NO>
<ARTICLE_EAN>5707644835962</ARTICLE_EAN>
<ARTICLE_DESCRIPTION></ARTICLE_DESCRIPTION>
<ARTICLE_DESCRIPTION2></ARTICLE_DESCRIPTION2>
<ARTICLE_ID>102406639</ARTICLE_ID>
<QUANTITY>500</QUANTITY>
<UNIT_OF_MEASURE>Pcs</UNIT_OF_MEASURE>
<LOT_NO></LOT_NO>
<EXPIRATION_DATE></EXPIRATION_DATE>
<LINE_CUSTOM_FIELDS>
<LINE_CUSTOM_FIELD1></LINE_CUSTOM_FIELD1>
...
<LINE_CUSTOM_FIELD5></LINE_CUSTOM_FIELD5>
</LINE_CUSTOM_FIELDS>
</LINE>
</LINES>
</ORDER>
</TOTHEM>
and I want it to end up like this:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <TOTHEM> <HEADER>
<TYPE>INSDES</TYPE>
<SENDER>me</SENDER>
<RECEIVER>Them</RECEIVER>
<DOCUMENT_REFERENCE>
<ID>5655850111</ID>
<TIMESTAMP>2022-11-30 11:42:52</TIMESTAMP>
</DOCUMENT_REFERENCE> </HEADER> <ORDER ID="TO-20402">
<EXTERNAL_DOCUMENT_NO></EXTERNAL_DOCUMENT_NO>
<REFERENCE>TO-20402</REFERENCE>
<ORDER_DATE>30-11-2022</ORDER_DATE>
<DELIVERY_DATE>30-11-2022</DELIVERY_DATE>
<PICK_COMMENT></PICK_COMMENT>
<CARRIER></CARRIER>
<SHIP>
<SHIP_ID>me</SHIP_ID>
<SHIP_NAME>me</SHIP_NAME>
<SHIP_NAME2></SHIP_NAME2>
<SHIP_ADDRESS>here</SHIP_ADDRESS>
<SHIP_ADDRESS2></SHIP_ADDRESS2>
<SHIP_POSTCODE>8600</SHIP_POSTCODE>
<SHIP_CITY>Silkeborg</SHIP_CITY>
<SHIP_COUNTRY_CODE>DK</SHIP_COUNTRY_CODE>
<SHIP_ATT></SHIP_ATT>
<SHIP_COMMENT></SHIP_COMMENT>
<SHIP_MAIL></SHIP_MAIL>
<SHIP_PHONE_NO></SHIP_PHONE_NO>
<SHIP_SMS></SHIP_SMS>
</SHIP>
<RECEIVE>
<RECEIVE_ID></RECEIVE_ID>
<RECEIVE_NAME></RECEIVE_NAME>
<RECEIVE_ADDRESS></RECEIVE_ADDRESS>
<RECEIVE_ADDERSS2></RECEIVE_ADDERSS2>
<RECEIVE_POSTCODE></RECEIVE_POSTCODE>
<RECEIVE_CITY></RECEIVE_CITY>
<RECEIVE_COUNTRY_CODE></RECEIVE_COUNTRY_CODE>
<RECEIVE_CONTACT></RECEIVE_CONTACT>
</RECEIVE>
<ORDER_CUSTOM_FIELDS>
<ORDER_CUSTOM_FIELD1></ORDER_CUSTOM_FIELD1>
...
<ORDER_CUSTOM_FIELD5></ORDER_CUSTOM_FIELD5>
</ORDER_CUSTOM_FIELDS>
<LINES>
<LINE ID="4054009">
<ARTICLE_NO>260250104</ARTICLE_NO>
<ARTICLE_EAN>5707644776470</ARTICLE_EAN>
<ARTICLE_DESCRIPTION></ARTICLE_DESCRIPTION>
<ARTICLE_DESCRIPTION2></ARTICLE_DESCRIPTION2>
<ARTICLE_ID>102406528</ARTICLE_ID>
<QUANTITY>150</QUANTITY>
<UNIT_OF_MEASURE>Pcs</UNIT_OF_MEASURE>
<LOT_NO></LOT_NO>
<EXPIRATION_DATE></EXPIRATION_DATE>
<LINE_CUSTOM_FIELDS>
<LINE_CUSTOM_FIELD1></LINE_CUSTOM_FIELD1>
...
<LINE_CUSTOM_FIELD5></LINE_CUSTOM_FIELD5>
</LINE_CUSTOM_FIELDS>
</LINE>
<LINE ID="4054010">
<ARTICLE_NO>164800001</ARTICLE_NO>
<ARTICLE_EAN>5707644835962</ARTICLE_EAN>
<ARTICLE_DESCRIPTION></ARTICLE_DESCRIPTION>
<ARTICLE_DESCRIPTION2></ARTICLE_DESCRIPTION2>
<ARTICLE_ID>102406639</ARTICLE_ID>
<QUANTITY>500</QUANTITY>
<UNIT_OF_MEASURE>Pcs</UNIT_OF_MEASURE>
<LOT_NO></LOT_NO>
<EXPIRATION_DATE></EXPIRATION_DATE>
<LINE_CUSTOM_FIELDS>
<LINE_CUSTOM_FIELD1></LINE_CUSTOM_FIELD1>
...
<LINE_CUSTOM_FIELD5></LINE_CUSTOM_FIELD5>
</LINE_CUSTOM_FIELDS>
</LINE>
</LINES>
</ORDER>
</TOTHEM>
But I'm not experienced enough in XSLT to make it happen... anyone have good ideas?
It is asking me for more details, but I have no idea what to write here.....
CodePudding user response:
This is very difficult to follow (too much code to read). I get the impression that all you want to do is move all LINEs, from all ORDERS, into the first ORDER and remove all other ORDERs. It doesn't seem to make much sense, but if you like it can be done easily:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/TOTHEM">
<xsl:copy>
<xsl:apply-templates select="HEADER | ORDER[1]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="LINES">
<xsl:copy>
<xsl:apply-templates select="//LINE"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>