Subject: Re: [xsl] XSL Condition is not working From: "Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 20 Jun 2017 18:03:41 -0000 |
For example, take <Alert__c> <Alert_Type__c>Document Downloaded</Alert_Type__c> <Document_Name__c>w.txt</Document_Name__c> </Alert__c>
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>
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/225679> (by email <>)
-- Gerrit Imsieke GeschC$ftsfC<hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930
GeschC$ftsfC<hrer: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt, Dr. Reinhard VC6ckler
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSL Condition is not working, Rahul Singh rahulsin | Thread | [xsl] XSLT at the XML Summer School, Priscilla Walmsley p |
[xsl] XSLT at the XML Summer School, Priscilla Walmsley p | Date | [xsl] Transform help, Joseph L. Casale jca |
Month |