[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: XSL Condition is not working
I donbt understand it fully. The output comprises all of merge1.xmlbs
Alter__c items because all meet your conditions.
Why do you expect that the output objects element contains only
Alert__c[Document_Name__c = 'abcTest.txt']]?
For example, take
<Alert__c>
<Alert_Type__c>Document Downloaded</Alert_Type__c>
<Document_Name__c>w.txt</Document_Name__c>
</Alert__c>
$Email_from_merge1 is 'Document Downloaded'
not(exists($XMLMerge2/objects/Data__c[Alert_Type__c =
$Email_from_merge1])) is true
because all Data__c in merge2.xml have an Alert_Type__c of 'Document Viewed'
$Email_from_merge2 is 'w.txt'
$XMLMerge2/objects/Data__c[Document_Name__c = 'w.txt'] exists (there are
two Data__c with Document_Name__c = 'w.txt').
So for this example both 'if' conditions are true, and for all other
Alert__c elements, too.
This explains the output, yet it doesnbt explain why it is different
from your expectations.
Gerrit
On 6/20/17 3:30 PM, Rahul Singh rahulsinghindia15@xxxxxxxxx wrote:
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|