[xsl] XSL Condition is not working

Subject: [xsl] XSL Condition is not working
From: "Rahul Singh rahulsinghindia15@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 20 Jun 2017 13:29:51 -0000
My xsl code is not working as per given expected output. I need data from
merge1.xml if Alert_Type__c='Document Downloaded' and
Document_Name__c='abcTest.txt' is match with merge2.xml with
Document_Name__c='abcTest.txt' and Alert_Type__c!='Document Downloaded'

Input
Merge1.xml:

     <?xml version="1.0" encoding="UTF-8"?>
     <objects>
     <Alert__c>
     <Alert_Type__c>Document Downloaded</Alert_Type__c>
     <Document_Name__c>b (2).txt</Document_Name__c>
     </Alert__c>
     <Alert__c>
     <Alert_Type__c>Document Downloaded</Alert_Type__c>
      <Document_Name__c>w.txt</Document_Name__c>
      </Alert__c>
      <Alert__c>
     <Alert_Type__c>Document Downloaded</Alert_Type__c>
     <Document_Name__c>w.txt</Document_Name__c>
     </Alert__c>
     <Alert__c>
      <Alert_Type__c>Document Downloaded</Alert_Type__c>
     <Document_Name__c>file 1.pdf</Document_Name__c>
     </Alert__c>
     <Alert__c>
     <Alert_Type__c>Document Downloaded</Alert_Type__c>
     <Document_Name__c>abcTest.txt</Document_Name__c>
     </Alert__c>
     <Alert__c>
     <Alert_Type__c>Document Downloaded</Alert_Type__c>
      <Document_Name__c>VICS_810_004010_US.pdf</Document_Name__c>
     </Alert__c>
     <Alert__c>
     <Alert_Type__c>Document Downloaded</Alert_Type__c>
     <Document_Name__c>VICS_810_004010_US.pdf</Document_Name__c>
      </Alert__c>
      </objects>

Merge2.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <objects>
    <Data__c>
    <Document_Name__c>abcTest.txt</Document_Name__c>
    <Alert_Type__c>Document Viewed</Alert_Type__c>
     </Data__c>
    <Data__c>
    <Document_Name__c>w.txt</Document_Name__c>
    <Alert_Type__c>Document Viewed</Alert_Type__c>
    </Data__c>
    <Data__c>
    <Document_Name__c>q.txt</Document_Name__c>
    <Alert_Type__c>Document Viewed</Alert_Type__c>
     </Data__c>
     <Data__c>
    <Document_Name__c>file 1.pdf</Document_Name__c>
    <Alert_Type__c>Document Viewed</Alert_Type__c>
    </Data__c>
    <Data__c>
    <Document_Name__c>DealRoomData.csv</Document_Name__c>
    <Alert_Type__c>Document Viewed</Alert_Type__c>
     </Data__c>
    <Data__c>
    <Document_Name__c>b (2).txt</Document_Name__c>
    <Alert_Type__c>Document Viewed</Alert_Type__c>
    </Data__c>
    <Data__c>
    <Document_Name__c>w.txt</Document_Name__c>
    <Alert_Type__c>Document Viewed</Alert_Type__c>
    </Data__c>
    <Data__c>
    <Document_Name__c>VICS_810_004010_US.pdf</Document_Name__c>
    <Alert_Type__c>Document Viewed</Alert_Type__c>
    </Data__c>
    <Data__c>
    <Document_Name__c>VICS_810_004010_US.pdf</Document_Name__c>
    <Alert_Type__c>Document Viewed</Alert_Type__c>
     </Data__c>
    </objects>

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";
exclude-result-prefixes="xs" version="2.0">
    <xsl:output method="xml" indent="yes"/>
    <xsl:param name="XMLMerge2" select="document('merge2.xml')"/>
    <xsl:template match="objects">
        <objects>
            <xsl:if test="
                    $XMLMerge2/objects != ''">
                <xsl:for-each select="Alert__c">
                    <xsl:variable name="Email_from_merge1"
select="Alert_Type__c"/>
                    <xsl:variable name="Email_from_merge2"
select="Document_Name__c"/>
                    <xsl:if

test="not(exists($XMLMerge2/objects/Data__c[Alert_Type__c =
$Email_from_merge1]))">
                        <xsl:if

test="exists($XMLMerge2/objects/Data__c[Document_Name__c =
$Email_from_merge2])">
                            <xsl:copy>
                                <xsl:apply-templates select="@* | node()"/>
                            </xsl:copy>
                        </xsl:if>
                    </xsl:if>
                </xsl:for-each>
            </xsl:if>
        </objects>
      </xsl:template>
      <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
     </xsl:template>
    </xsl:stylesheet>

Expected  output:

     <?xml version="1.0" encoding="UTF-8"?>
     <objects>
    <Alert__c>
    <Alert_Type__c>Document Downloaded</Alert_Type__c>
    <Document_Name__c>abcTest.txt</Document_Name__c>
     </Alert__c>
    </objects>

Current Thread