Condition based filtering for the target field - xslt

Below is my xml input
<?xml version="1.0" encoding="UTF-8"?>
<DELVRY07>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM>EDI_DC40</TABNAM>
<MANDT>100</MANDT>
</EDI_DC40>
<E1EDL20 SEGMENT="1">
<VBELN>0080000646</VBELN>
<VSTEL>1710</VSTEL>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>AG</PARTNER_Q>
<PARTNER_ID>0017100001</PARTNER_ID>
<JURISDIC>GA00000000</JURISDIC>
<LANGUAGE>EN</LANGUAGE>
<FORMOFADDR>Company</FORMOFADDR>
<NAME1>Domestic US Customer 1</NAME1>
</E1ADRM1>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>SP</PARTNER_Q>
<PARTNER_ID>PL1047</PARTNER_ID>
<LANGUAGE>EN</LANGUAGE>
<NAME1>W. L. GORE & ASSOCIATES, INC</NAME1>
</E1ADRM1>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>WE</PARTNER_Q>
<PARTNER_ID>0017100001</PARTNER_ID>
<JURISDIC>GA00000000</JURISDIC>
<LANGUAGE>EN</LANGUAGE>
<FORMOFADDR>Company</FORMOFADDR>
<NAME1>Domestic US Customer 1</NAME1>
</E1ADRM1>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>OSP</PARTNER_Q>
<PARTNER_ID>1710</PARTNER_ID>
<JURISDIC>7700000000</JURISDIC>
<LANGUAGE>EN</LANGUAGE>
<NAME1>Shipping Point 1710 - Address Name 1</NAME1>
</E1ADRM1>
<E1ADRM1 SEGMENT="1">
<PARTNER_Q>OSO</PARTNER_Q>
<PARTNER_ID>1710</PARTNER_ID>
<JURISDIC>7700000000</JURISDIC>
<LANGUAGE>EN</LANGUAGE>
<NAME1>Sales Organization 1710 - Address Name 1</NAME1>
</E1ADRM1>
</E1EDL20></IDOC></DELVRY07>
in the above xml I need to filter out the condtion for PARTNER_Q. if PARTNER_Q =WE then pass the value of related NAME1 field value to the target.
I have tried below XSL code but not able get the correct logic for filtering
<xsl:variable name="vPartnerfunction" select="$nodes_in/PARTNER_Q"/>
<xsl:variable name="vName" select="$nodes_in/NAME1"/>
<xsl:choose>
<xsl:when test="$vPartnerfunction = 'WE'">
<xsl:value-of select="$vName"/>
</xsl:when>
</xsl:choose>
Please help me out on this.
In the output only i should get the below value
<NAME1>Domestic US Customer 1</NAME1>

The result you show can be produced quite easily by:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/DELVRY07">
<xsl:copy-of select="IDOC/E1EDL20/E1ADRM1[PARTNER_Q='WE']/NAME1"/>
</xsl:template>
</xsl:stylesheet>
However, if there are more than one E1ADRM1 element that meets the condition, the result will be an XML fragment - not a well-formed XML document.

Related

XSL to replace value by condition

I want to replace the contents of /SHPMNT05/IDOC/E1EDT20/E1EDL20/E1EDL37/E1EDL44/CUOBJ with the value of /SHPMNT05/IDOC/E1EDT20/E1EDL20/E1EDL24/E1EDL43/BELNR but the best I can get is a 'true' with my xsl transformation :(
My xml:
<SHPMNT05>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>0000287302</TKNUM>
<E1EDL20 SEGMENT="1">
<VBELN>0081018991</VBELN>
<E1EDL24 SEGMENT="1">
<POSNR>000010</POSNR>
<MATNR>000000000000009645</MATNR>
<E1EDL43 SEGMENT="1">
<BELNR>0003196597</BELNR>
</E1EDL43>
</E1EDL24>
<E1EDL24 SEGMENT="1">
<POSNR>000020</POSNR>
<MATNR>000000000000009646</MATNR>
<E1EDL43 SEGMENT="1">
<BELNR>0003196598</BELNR>
</E1EDL43>
</E1EDL24>
<E1EDL37 SEGMENT="1">
<EXIDV>00387112831000247463</EXIDV>
<E1EDL44 SEGMENT="1">
<VBELN>0081018991</VBELN>
<POSNR>000010</POSNR>
<CUOBJ>000000000000000000</CUOBJ>
</E1EDL44>
</E1EDL37>
<E1EDL37 SEGMENT="1">
<EXIDV>00387112831000247470</EXIDV>
<E1EDL44 SEGMENT="1">
<VBELN>0081018991</VBELN>
<POSNR>000020</POSNR>
<VEMNG>5000.000</VEMNG>
<CUOBJ>000000000000000000</CUOBJ>
</E1EDL44>
</E1EDL37>
</E1EDL20>
</E1EDT20>
</IDOC>
</SHPMNT05>
My xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="node()|#*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="node()|#*" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/SHPMNT05/IDOC/E1EDT20/E1EDL20/E1EDL37/E1EDL44/CUOBJ">
<CUOBJ> <xsl:value-of select="ancestor::node()[3]/VBELN=../VBELN and ancestor::node()[3]/E1EDL24/POSNR=../POSNR"/></CUOBJ>
<xsl:for-each select="//E1EDL44">
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Current result:
<SHPMNT05>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>0000287302</TKNUM>
<E1EDL20 SEGMENT="1">
<VBELN>0081018991</VBELN>
<E1EDL24 SEGMENT="1">
<POSNR>000010</POSNR>
<MATNR>000000000000009645</MATNR>
<E1EDL43 SEGMENT="1">
<BELNR>0003196597</BELNR>
</E1EDL43>
</E1EDL24>
<E1EDL24 SEGMENT="1">
<POSNR>000020</POSNR>
<MATNR>000000000000009646</MATNR>
<E1EDL43 SEGMENT="1">
<BELNR>0003196597</BELNR>
</E1EDL43>
</E1EDL24>
<E1EDL37 SEGMENT="1">
<EXIDV>00387112831000247463</EXIDV>
<E1EDL44 SEGMENT="1">
<VBELN>0081018991</VBELN>
<POSNR>000010</POSNR>
<CUOBJ>true</CUOBJ>
</E1EDL44>
</E1EDL37>
<E1EDL37 SEGMENT="1">
<EXIDV>00387112831000247470</EXIDV>
<E1EDL44 SEGMENT="1">
<VBELN>0081018991</VBELN>
<POSNR>000020</POSNR>
<VEMNG>5000.000</VEMNG>
<CUOBJ>true</CUOBJ>
</E1EDL44>
</E1EDL37>
</E1EDL20>
</E1EDT20>
</IDOC>
</SHPMNT05>
Required result:
<SHPMNT05>
<IDOC BEGIN="1">
<E1EDT20 SEGMENT="1">
<TKNUM>0000287302</TKNUM>
<E1EDL20 SEGMENT="1">
<VBELN>0081018991</VBELN>
<E1EDL24 SEGMENT="1">
<POSNR>000010</POSNR>
<MATNR>000000000000009645</MATNR>
<E1EDL43 SEGMENT="1">
<BELNR>0003196597</BELNR>
</E1EDL43>
</E1EDL24>
<E1EDL24 SEGMENT="1">
<POSNR>000020</POSNR>
<MATNR>000000000000009646</MATNR>
<E1EDL43 SEGMENT="1">
<BELNR>0003196598</BELNR>
</E1EDL43>
</E1EDL24>
<E1EDL37 SEGMENT="1">
<EXIDV>00387112831000247463</EXIDV>
<E1EDL44 SEGMENT="1">
<VBELN>0081018991</VBELN>
<POSNR>000010</POSNR>
<CUOBJ>0003196597</CUOBJ>
</E1EDL44>
</E1EDL37>
<E1EDL37 SEGMENT="1">
<EXIDV>00387112831000247470</EXIDV>
<E1EDL44 SEGMENT="1">
<VBELN>0081018991</VBELN>
<POSNR>000020</POSNR>
<VEMNG>5000.000</VEMNG>
<CUOBJ>0003196598</CUOBJ>
</E1EDL44>
</E1EDL37>
</E1EDL20>
</E1EDT20>
</IDOC>
</SHPMNT05>
Link: https://xsltfiddle.liberty-development.net/aUPRNr
I'm afraid I made a mess with the ancestor::node()[3] part...
Each time I think I'learning something / know how 'to fix it' the challenge becomes too big :(
Update: forgot to mention. there can be more E1EDL44 than E1EDL24 elements. SAP Idoc always starts with E1EDL24 'lines' which shows the lines in a delivery. Then you get E1EDL37 Handling units below with 1 or more E1EDL44 lines on that handling unit. The relation between 24 and 44 is on POSNR.
Also there can be multiple E1EDL20 elements (deliveries) each with e.g. an E1EDL24 with POSNR 10. So the combination E1EDL20\VBELN E1EDL24\POSNR is unique. There is only one E1EDL43 in E1EDL24.
Kind regards,
Mike
-- edited in view of clarifications --
So, now that we know that there exists a cross-reference between E1EDL24 and E1EDL44 in the form of a common value of POSNR, we can use a key to implement a link between the two.
And, since the value of POSNR is unique only within the E1EDT20 branch, we need to include the unique id of the branch in the key:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="e1edl24" match="E1EDL24" use="concat(POSNR, '|', generate-id(ancestor::E1EDT20))" />
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="CUOBJ">
<xsl:copy>
<xsl:value-of select="key('e1edl24', concat(../POSNR, '|', generate-id(ancestor::E1EDT20)))/E1EDL43/BELNR"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

How to Concat similar node values in XML using XSLT

I have a Source XML like below.
<Root>
<E1 SEGMENT="1">
<Node1>SomeValue</Node1>
<Node2>I</Node2>
<Node3>IT</Node3>
<E2 SEGMENT="1">
<TLINE>Val1</TLINE>
<TF>*</TF>
</E2>
<E2 SEGMENT="1">
<TLINE>Val2</TLINE>
<TF>*</TF>
</E2>
<E2 SEGMENT="1">
<TLINE>Val3</TLINE>
<TF>*</TF>
</E2>
.....
.....
......
</E1>
</Root>
Expecting Output as below. source might be having more than 3 occurrences of E2 segment.
want to combine TLINE Values with a delimiter using XSLT.
<Root>
<E1 SEGMENT="1">
<Node1>SomeValue</Node1>
<Node2>I</Node2>
<Node3>IT</Node3>
<E2 SEGMENT="1">
<TLINE>Val1 | Val2 | Val3 |...</TLINE>
<TF>*;*;*</TF>
</E2>
</E1>
</Root>
any help will be appreciated.

XSLT copy-of doesn't match document

I'm receiving a large XML with many documents and I need to break it down to single documents for processing. I'm using XSLT. In the source /ACC_DOCUMENT04/IDOC is a recurring element, but in each result of the transform it would a singular.
I'm using XSLT 1.0 with an input parameter, and I've done similar ones before, but I cannot figure out why my transform doesn't find any data at all. This is my latest attempt: https://xsltfiddle.liberty-development.net/eixh2wH
Input XML:
<?xml version="1.0" encoding="UTF-8"?>
<ACC_DOCUMENT04>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM>EDI_DC40</TABNAM>
<DIRECT>2</DIRECT>
<IDOCTYP>ACC_DOCUMENT04</IDOCTYP>
<MESTYP>ACC_DOCUMENT</MESTYP>
<MESFCT/>
<SNDPOR>SAPXQ1</SNDPOR>
<SNDPRT>LS</SNDPRT>
<SNDPRN>MAGENTO</SNDPRN>
<RCVPOR>SAPEQ1</RCVPOR>
<RCVPRT>LS</RCVPRT>
<RCVPRN>EQ1CLNT400</RCVPRN>
</EDI_DC40>
<E1BPACHE09 SEGMENT="1">
<OBJ_TYPE>BKPFF</OBJ_TYPE>
<OBJ_KEY>FB01</OBJ_KEY>
<BUS_ACT>RFBU</BUS_ACT>
<USERNAME>SAPPI</USERNAME>
<HEADER_TXT>SL000000601</HEADER_TXT>
<COMP_CODE>1713</COMP_CODE>
<DOC_DATE>20220701</DOC_DATE>
<PSTNG_DATE>20220701</PSTNG_DATE>
<TRANS_DATE>20220701</TRANS_DATE>
<FISC_YEAR>2022</FISC_YEAR>
<DOC_TYPE>ZM</DOC_TYPE>
<REF_DOC_NO>SL000001861</REF_DOC_NO>
</E1BPACHE09>
<E1BPACGL09 SEGMENT="1">
<ITEMNO_ACC>1</ITEMNO_ACC>
<GL_ACCOUNT>0012100050</GL_ACCOUNT>
<ITEM_TEXT>NK9HZT53LLBX8N82</ITEM_TEXT>
<REF_KEY_1>MC</REF_KEY_1>
<VALUE_DATE>20220701</VALUE_DATE>
<ALLOC_NMBR>SL000001861</ALLOC_NMBR>
</E1BPACGL09>
<E1BPACAR09 SEGMENT="1">
<ITEMNO_ACC>2</ITEMNO_ACC>
<CUSTOMER>0001077997</CUSTOMER>
<PAYMT_REF>SL000001861</PAYMT_REF>
<ALLOC_NMBR>SL000001861</ALLOC_NMBR>
<ITEM_TEXT>NK9HZT53LLBX8N82</ITEM_TEXT>
</E1BPACAR09>
<E1BPACCR09 SEGMENT="1">
<ITEMNO_ACC>1</ITEMNO_ACC>
<CURRENCY>USD</CURRENCY>
<AMT_DOCCUR>14.65</AMT_DOCCUR>
</E1BPACCR09>
<E1BPACCR09 SEGMENT="1">
<ITEMNO_ACC>2</ITEMNO_ACC>
<CURRENCY>USD</CURRENCY>
<AMT_DOCCUR>-14.65</AMT_DOCCUR>
</E1BPACCR09>
</IDOC>
<IDOC BEGIN="2">
<EDI_DC40 SEGMENT="2">
<TABNAM>EDI_2</TABNAM>
<DIRECT>2</DIRECT>
<IDOCTYP>ACC_DOCUMENT04</IDOCTYP>
<MESTYP>ACC_DOCUMENT</MESTYP>
<MESFCT/>
<SNDPOR>SAPXQ1</SNDPOR>
<SNDPRT>LS</SNDPRT>
<SNDPRN>MAGENTO</SNDPRN>
<RCVPOR>SAPEQ1</RCVPOR>
<RCVPRT>LS</RCVPRT>
<RCVPRN>EQ1CLNT400</RCVPRN>
</EDI_DC40>
<E1BPACHE09 SEGMENT="1">
<OBJ_TYPE>BKPFF</OBJ_TYPE>
<OBJ_KEY>FB01</OBJ_KEY>
<BUS_ACT>RFBU</BUS_ACT>
<USERNAME>SAPPI</USERNAME>
<HEADER_TXT>SL000000598</HEADER_TXT>
<COMP_CODE>1713</COMP_CODE>
<DOC_DATE>20220701</DOC_DATE>
<PSTNG_DATE>20220701</PSTNG_DATE>
<TRANS_DATE>20220701</TRANS_DATE>
<FISC_YEAR>2022</FISC_YEAR>
<DOC_TYPE>ZM</DOC_TYPE>
<REF_DOC_NO>SL000001864</REF_DOC_NO>
</E1BPACHE09>
<E1BPACGL09 SEGMENT="1">
<ITEMNO_ACC>1</ITEMNO_ACC>
<GL_ACCOUNT>0012100050</GL_ACCOUNT>
<ITEM_TEXT>W82RKHDLHRWZNN82</ITEM_TEXT>
<REF_KEY_1>MC</REF_KEY_1>
<VALUE_DATE>20220701</VALUE_DATE>
<ALLOC_NMBR>SL000001864</ALLOC_NMBR>
</E1BPACGL09>
<E1BPACAR09 SEGMENT="1">
<ITEMNO_ACC>2</ITEMNO_ACC>
<CUSTOMER>0001077997</CUSTOMER>
<PAYMT_REF>SL000001864</PAYMT_REF>
<ALLOC_NMBR>SL000001864</ALLOC_NMBR>
<ITEM_TEXT>W82RKHDLHRWZNN82</ITEM_TEXT>
</E1BPACAR09>
<E1BPACCR09 SEGMENT="1">
<ITEMNO_ACC>1</ITEMNO_ACC>
<CURRENCY>USD</CURRENCY>
<AMT_DOCCUR>56.21</AMT_DOCCUR>
</E1BPACCR09>
<E1BPACCR09 SEGMENT="1">
<ITEMNO_ACC>2</ITEMNO_ACC>
<CURRENCY>USD</CURRENCY>
<AMT_DOCCUR>-56.21</AMT_DOCCUR>
</E1BPACCR09>
</IDOC>
</ACC_DOCUMENT04>
Transform:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="Doc" select="SL000000598" />
<xsl:template match="/ACC_DOCUMENT04">
<ACC_DOCUMENT04>
<xsl:copy-of select="./IDOC[E1BPACHE09/HEADER_TXT=$Doc]"/>
</ACC_DOCUMENT04>
</xsl:template>
</xsl:stylesheet>
The expected output would be just the second IDOC, so abbreviated:
<?xml version="1.0" encoding="UTF-8"?>
<ACC_DOCUMENT04>
<IDOC BEGIN="2">
...
<E1BPACHE09 SEGMENT="1">
...
<HEADER_TXT>SL000000598</HEADER_TXT>
<REF_DOC_NO>SL000001864</REF_DOC_NO>
...
</E1BPACHE09>
...
</IDOC>
</ACC_DOCUMENT04>
Change:
<xsl:param name="Doc" select="SL000000598" />
to:
<xsl:param name="Doc" select="'SL000000598'" />
or:
<xsl:param name="Doc">SL000000598"</xsl:param>
What you have now is looking for a root element named SL000000598.
Note that there should be no problem if you leave it as it is - or change it to <xsl:param name="Doc"/> - and pass the value as the parameter at runtime. It's only your hard-coded test that fails.

Grouping by concatination of two fields in XSLT 1.0

I'm in big trouble with a task I should fulfill and tryed it for several days now. I would be very grateful to anyone who can help with the solution.
Problem
I need to group values together within a XSL transformation (XSLT 1.0). Of course I searched the forum and web so I found that I have to do it with muenchian grouping. I just can't get managed to get it running on my own.
Filling the field YCSSTKLID with grouped values:
YCSSTKLID need to be filled with a concatenation out of "ESN" + "GRAPHIC_NAME" (e.g '123#1' for ESN '123' and GRAPHIC_NAME '1.png'
Every combination of ESN + GRAPHIC_NAME must only be contained a single time, so the duplicates need to be removed
A ESN can have multiple associated GRAPHIC_NAMES
A GRAPHIC_NAME can belong to multiple ESN
Simplified Source
<?xml version="1.0" encoding="utf-8"?>
<ns:MT_FlatFile_Lists_Cu xmlns:ns="urn:las:pp:ss1:tar">
<Cu_Records>
<Record>
<ESN>123</ESN>
<GRAPHIC_NAME>1.png</GRAPHIC_NAME>
<LEVEL_NO>1</LEVEL_NO>
<CALLOUT></CALLOUT>
</Record>
<Record>
<ESN>123</ESN>
<GRAPHIC_NAME>2.png</GRAPHIC_NAME>
<LEVEL_NO>2</LEVEL_NO>
<CALLOUT></CALLOUT>
</Record>
<Record>
<ESN>123</ESN>
<GRAPHIC_NAME>2.png</GRAPHIC_NAME>
<LEVEL_NO>3</LEVEL_NO>
<CALLOUT>3</CALLOUT>
</Record>
<Record>
<ESN>456</ESN>
<GRAPHIC_NAME>2.png</GRAPHIC_NAME>
<LEVEL_NO>1</LEVEL_NO>
<CALLOUT></CALLOUT>
</Record>
<Record>
<ESN>456</ESN>
<GRAPHIC_NAME>2.png</GRAPHIC_NAME>
<LEVEL_NO>2</LEVEL_NO>
<CALLOUT>17</CALLOUT>
</Record>
<Record>
<ESN>456</ESN>
<GRAPHIC_NAME>3.png</GRAPHIC_NAME>
<LEVEL_NO>2</LEVEL_NO>
<CALLOUT>18</CALLOUT>
</Record>
</Cu_Records>
</ns:MT_FlatFile_Lists_Cu>
Desired Output
<?xml version="1.0" encoding="UTF-8"?>
<YCSMKO01>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<SNDPOR></SNDPOR>
<SNDPRT></SNDPRT>
<SNDPRN></SNDPRN>
<SNDLAD></SNDLAD>
</EDI_DC40>
<YCSMOTOR_KONF01 SEGMENT="1">
<YCSMOTOR_KONF02 SEGMENT="1">
<YCSSTKLID>123#1</YCSSTKLID>
</YCSMOTOR_KONF02>
<YCSMOTOR_KONF02 SEGMENT="1">
<YCSSTKLID>123#2</YCSSTKLID>
</YCSMOTOR_KONF02>
</YCSMOTOR_KONF01>
</IDOC>
</YCSMKO01>
<YCSMKO01>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<SNDPOR></SNDPOR>
<SNDPRT></SNDPRT>
<SNDPRN></SNDPRN>
<SNDLAD></SNDLAD>
</EDI_DC40>
<YCSMOTOR_KONF01 SEGMENT="1">
<YCSMOTOR_KONF02 SEGMENT="1">
<YCSSTKLID>456#2</YCSSTKLID>
</YCSMOTOR_KONF02>
<YCSMOTOR_KONF02 SEGMENT="1">
<YCSSTKLID>456#3</YCSSTKLID>
</YCSMOTOR_KONF02>
</YCSMOTOR_KONF01>
</IDOC>
</YCSMKO01>
Reduced example XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" xmlns:xsltc="http://xml.apache.org/xalan/xsltc" xmlns:map="java.util.Map" xmlns:dyn="com.sap.aii.mapping.api.DynamicConfiguration" xmlns:key="com.sap.aii.mapping.api.DynamicConfigurationKey" xmlns:ns="urn:las:pp:ss1:tar" exclude-result-prefixes="xs ns xsl map key dyn xsltc">
<xsl:output indent="yes"/>
<xsl:key name="a" match="Record" use="ESN"/>
<xsl:key name="grouping" match="/ns:MT_FlatFile_Lists_Cu/Cu_Records/Record" use="concat(./ESN, ./GRAPHIC_NAME)"/>
<xsl:template match="/">
<xsl:apply-templates select="/ns:MT_FlatFile_Lists_Cu/Cu_Records/Record[generate-id(.) = generate-id(key('a', ESN))]" mode="head">
</xsl:apply-templates>
</xsl:template>
<!-- IDoc-Struktur -->
<xsl:template match="Record" mode="head">
<xsl:param name="pTime"/>
<xsl:variable name="esn" select="ESN"/>
<YCSMKO01>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<SNDPOR></SNDPOR>
<SNDPRT></SNDPRT>
<SNDPRN></SNDPRN>
<SNDLAD></SNDLAD>
</EDI_DC40>
<YCSMOTOR_KONF01 SEGMENT="1">
<KLU>TBD</KLU>
<TYP>TBD</TYP>
<YCSMOTOR_KONF02 SEGMENT="1">
<YCSSTKLID>
<xsl:value-of select="concat(ESN,'#',substring-before(GRAPHIC_NAME, '.'))"/>
</YCSSTKLID>
</YCSMOTOR_KONF02>
<!-- Test Muenchian grouping -->
<xsl:for-each select="/ns:MT_FlatFile_Lists_Cu/Cu_Records/Record[generate-id(key('grouping, concat(./ESN, ./GRAPHIC_NAME)))]"/>
<YCSMOTOR_KONF02 SEGMENT="1">
<YCSSTKLID>
<xsl:value-of select="concat(./ESN,'#',substring-before(./GRAPHIC_NAME, '.'))"/>
</YCSSTKLID>
</YCSMOTOR_KONF02>
<!-- End Muenchian -->
</YCSMOTOR_KONF01>
</IDOC>
</YCSMKO01>
</xsl:template>
</xsl:stylesheet>
Thank you very much in advance.
If I am guessing correctly, you want to do something like:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="urn:las:pp:ss1:tar"
exclude-result-prefixes="ns">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="rec-by-esn" match="Record" use="ESN"/>
<xsl:key name="rec-by-grf" match="Record" use="concat(ESN, '|', GRAPHIC_NAME)"/>
<xsl:template match="/ns:MT_FlatFile_Lists_Cu">
<root>
<!-- group by ESN -->
<xsl:for-each select="Cu_Records/Record[generate-id() = generate-id(key('rec-by-esn', ESN))]">
<YCSMKO01>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<SNDPOR></SNDPOR>
<SNDPRT></SNDPRT>
<SNDPRN></SNDPRN>
<SNDLAD></SNDLAD>
</EDI_DC40>
<!-- subgroup by ESN and GRAPHIC_NAME -->
<xsl:for-each select="key('rec-by-esn', ESN)[generate-id() = generate-id(key('rec-by-grf', concat(ESN, '|', GRAPHIC_NAME)))]">
<YCSMOTOR_KONF02 SEGMENT="1">
<YCSSTKLID>
<xsl:value-of select="concat(ESN,'#',substring-before(GRAPHIC_NAME, '.'))"/>
</YCSSTKLID>
</YCSMOTOR_KONF02>
</xsl:for-each>
</IDOC>
</YCSMKO01>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
Note the way subgrouping is applied to the current group only, selected by the expression key('rec-by-esn', ESN).

Remove top 2 elements along with namespace using XSLT

I have an input XML as shown below
<ns9:Messages xmlns:ns9="http://sap.com/xi/XI/SplitAndMerge">
<ns9:Message1>
<ZCOD_SERVICE_CONFIRMATION02>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<DIRECT>2</DIRECT>
<MESTYP>COD_SERVICE_CONFIRMATION</MESTYP>
</EDI_DC40>
<E101COD_S_SRV_CONF SEGMENT="1">
<REFOBJKEY>0000122425</REFOBJKEY>
<REFDOCTYPE>L2</REFDOCTYPE>
</E101COD_S_SRV_CONF>
</IDOC>
</ZCOD_SERVICE_CONFIRMATION02>
</ns9:Message1>
</ns9:Messages>
I need the output to be as below, essentially removing the top 2 elements and the namespace. I am able to do it by applying 2 XSLT one after another, but how can I do it using one XSLT.
Please note I can not use template match on the 3rd level node (ZCOD_SERVICE_CONFIRMATION02) as this name can be anything in runtime.
<?xml version="1.0"?>
<ZCOD_SERVICE_CONFIRMATION02>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<DIRECT>2</DIRECT>
<MESTYP>COD_SERVICE_CONFIRMATION</MESTYP>
</EDI_DC40>
<E101COD_S_SRV_CONF SEGMENT="1">
<REFOBJKEY>0000122425</REFOBJKEY>
<REFDOCTYPE>L2</REFDOCTYPE>
</E101COD_S_SRV_CONF>
</IDOC>
</ZCOD_SERVICE_CONFIRMATION02>
Best regards, Abinash
Assuming that the name and namespace of your 2nd level node is fixed (ns9:Message1), you could apply the following XSLT:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns9="http://sap.com" version="2.0">
<xsl:output exclude-result-prefixes="ns9" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of copy-namespaces="no" select="//*[parent::ns9:Message1]"/>
</xsl:template>
</xsl:stylesheet>