Remove top 2 elements along with namespace using XSLT - 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>

Related

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.

Condition based filtering for the target field

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.

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).

Add Values of a field specific to input value of another field

I have a requirement which is to be achieved using xslt. It requires to add only those values of field 'NETWR' under E1EDP01, when another field WERKS under E1EDP01 satisfies a certain condition. This added sum is to be populated under different node field SUMME under E1EDS01 (Occurrence of E1EDS01 is only one). Condition for WERKS is , it must have value = VK10 0r VK11 0r VK12 or (VK13 and IDTNR is not blank). I tried with below XSLT code but it gives me value '0'in output.Could anyone please help?
XSLT I used:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<ZNUMBER>
<IDOC>
<xsl:for-each select="Z_MM/IDOC/E1EDS01">
<E1EDS01>
<SUMME>
<xsl:value-of select="sum(Z_MM/IDOC/E1EDP01[(WERKS=&apos;VK13&apos; and E1EDP19/IDTNR!=&apos;&apos;) or WERKS = &apos;VK10&apos; or WERKS = &apos;VK11&apos; or WERKS = &apos;VK12&apos; ]/#NETWR)"/>
</SUMME>
</E1EDS01>
</xsl:for-each>
</IDOC>
</ZNUMBER>
</xsl:template>
</xsl:stylesheet>
INPUT XML:
<?xml version="1.0" encoding="UTF-8"?>
<Z_MM>
<IDOC BEGIN="1">
<E1EDP01 SEGMENT="1">
<NETWR>20</NETWR>
<WERKS>VK13</WERKS>
<E1EDP19 SEGMENT="1">
<IDTNR>000000000000211087</IDTNR>
</E1EDP19>
</E1EDP01>
<E1EDP01 SEGMENT="1">
<NETWR>10</NETWR>
<WERKS>VK11</WERKS>
<E1EDP19 SEGMENT="1">
<QUALF>001</QUALF>
</E1EDP19>
</E1EDP01>
<E1EDS01 SEGMENT="1">
<SUMID>002</SUMID>
<SUMME></SUMME>
<SUNIT></SUNIT>
</E1EDS01>
</IDOC>
</Z_MM>
OUTPUT should come as 20+10=30
Your current sum function is within an xsl:for-each in which you select E1EDS01 elements, so you expression is relative to that. In other words, it is looking for a child element of E1EDS01 called ZM1. If you want to search outside the current element, precede the expression / to start at the document node again. Additionally your expression is currently summing #NEWTR which is an attribute, whereas in your XML it is an element.
Try this expression.
<xsl:value-of select="sum(/Z_MM/IDOC/E1EDP01[(WERKS='VK13' and E1EDP19/IDTNR!='') or WERKS = 'VK10' or WERKS = 'VK11' or WERKS = 'VK12']/NETWR)"/>
Having said that, looking at your current XSLT, you don't really need the xsl:for-each at all in this case, as you say there is only one E1EDS01 and you are not actually using any value in it anyway.
Try this XSLT (The / is not needed here now, because you would already be positioned on the document node).
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<ZNUMBER>
<IDOC>
<E1EDS01>
<SUMME>
<xsl:value-of select="sum(Z_MM/IDOC/E1EDP01[(WERKS='VK13' and E1EDP19/IDTNR!='') or WERKS = 'VK10' or WERKS = 'VK11' or WERKS = 'VK12']/NETWR)"/>
</SUMME>
</E1EDS01>
</IDOC>
</ZNUMBER>
</xsl:template>
</xsl:stylesheet>
Alternatively, if you XSLT is a sample, and you actually just want to populate the existing SUMME, you could do this with the identity template, and an extra template to match SUMME.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="SUMME">
<xsl:copy>
<xsl:value-of select="sum(/Z_MM/IDOC/E1EDP01[(WERKS='VK13' and E1EDP19/IDTNR!='') or WERKS = 'VK10' or WERKS = 'VK11' or WERKS = 'VK12']/NETWR)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Restrict occurrence of Line item based on input condition in xslt

I need to populate the line item E1EP01 in output structure only if the value of E1EP01/CODE = WK30 and E1EP01/E1EP19/TEXT is not blank , in input file.
I have written below line of codes but E1EP01 is not appearing in Output even if CODE has value equal to WK30 and TEXT is not blank
Can anyone please help me in this?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<ORDERS05>
<IDOC>
<xsl:if test=" ZXX/IDOC/E1EP01/CODE = &apos;WK30&apos; and ZXX/IDOC/E1EP01/E1EP19/TEXT!= &apos; &apos;">
<xsl:for-each select="E1EP01">
<E1EP01>
<POSEX>
<xsl:value-of select="ZXX/IDOC/E1EP01/POSEX"/>
</POSEX>
</E1EP01>
</xsl:for-each>
</xsl:if>
</IDOC>
</ORDERS05>
</xsl:template>
</xsl:stylesheet>
Sample input is shown below:
<?xml version="1.0" encoding="UTF-8"?>
<ZXX>
<IDOC BEGIN="1">
<E1EP01 SEGMENT="1">
<POSEX>00020</POSEX>
<CODE>WN14</WERKS>
<E1EP19 SEGMENT="1">
<Q>001</Q>
<TEXT>000000000000204034</TEXT>
</E1EP19>
</E1EP01>
<E1EP01 SEGMENT="1">
<POSEX>00010</POSEX>
<WERKS>WK30</WERKS>
<E1EP19 SEGMENT="1">
<Q>001</Q>
<TEXT>000000000000205115</TEXT>
</E1EP19>
</E1EP01>
</IDOC>
</ZXX>
Change:
<xsl:for-each select="E1EP01">
to:
<xsl:for-each select="ZXX/IDOC/E1EP01">
Note: you don't need to escape single quotes as &apos; in your test expression.
Added:
I need to test each E1EP01 for the condition and if condition matches
then that E1EP01 should appear in output.
Try it this way, then:
XSLT 1.0
<xsl:stylesheet version="2.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="/ZXX">
<ORDERS05>
<IDOC>
<xsl:for-each select="IDOC/E1EP01[CODE='WK30' and E1EP19/TEXT!='']">
<xsl:copy>
<xsl:copy-of select="POSEX"/>
</xsl:copy>
</xsl:for-each>
</IDOC>
</ORDERS05>
</xsl:template>
</xsl:stylesheet>