XPATH: multiple negations in for-each

Posted by Peter on Stack Overflow See other posts from Stack Overflow or by Peter
Published on 2012-03-21T10:33:31Z Indexed on 2012/03/21 11:30 UTC
Read the original article Hit count: 290

Filed under:
|
|

I have the following simplified XML:

<?xml version="1.0" encoding="UTF-8" ?>
<MATMAS05>
<IDOC BEGIN="1">
    <E1MARAM SEGMENT="1">
        <MSGFN>005</MSGFN>
        <MATNR>000000000000401436</MATNR>
        <E1MARCM SEGMENT="1">
            <MSGFN>005</MSGFN>
            <WERKS>A120</WERKS>
            <MMSTA>01</MMSTA>
        </E1MARCM>
        <E1MVKEM SEGMENT="1">
            <VKORG>0120</VKORG>
            <VMSTA>04</VMSTA>
        </E1MVKEM>
    </E1MARAM>
</IDOC>
</MATMAS05>

If <WERKS>=A120 and <MMSTA> is NOT '01' or '02' or '03' OR if <VKORG>=0120 and <VMSTA> is NOT '01' or '02' or '03' then the <MATNR> should be mapped to the target XML.

I came up with the following XSLT:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="UTF-8" method="xml" indent="yes"/>

<xsl:template match="/*">
    <xsl:for-each
        select="IDOC[(E1MARAM/E1MVKEM[VKORG='0120'][not(VMSTA='01' or VMSTA='02' or VMSTA='03')])
            or (E1MARAM/E1MARCM[WERKS = 'A120'][not(MMSTA='01' or MMSTA='02' or MMSTA='03')])]">
        <Item>
            <ITEM_CODE>
                <xsl:value-of select="E1MARAM/MATNR"/>
            </ITEM_CODE>
        </Item>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

But if I apply that XSLT I get the following unwanted output (because <MMSTA>='01'):

<?xml version="1.0" encoding="UTF-8"?>
<Item>
<ITEM_CODE>000000000000401436</ITEM_CODE>
</Item>

How can I solve this? I have tried around with that XPATH expression but I can't get the wanted result. What am I doing wrong in my XPATH?

Thank you for any ideas with this. Best regards, Peter

© Stack Overflow or respective owner

Related posts about xslt

Related posts about xpath