[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSL Condition is not working

Subject: XSL Condition is not working
From: "Rahul Singh rahulsinghindia15@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 20 Jun 2017 13:29:51 -0000
 XSL Condition is not working
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.