Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2012, 03:59 PM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default comparing nodes and copying

Hi,

I have the following input xml

<POLICIES>
<COVERAGES>
<COVERAGE RBID="304135114_304134218" NAME="V02:CALCULATION">
<COVFORMULAINDEX FORMREF="EPL"/>
<COVINPUTS>
<FLD NM="EPL_RI_SGEXS">2500.0000</FLD>
<FLD NM="EPL_QF_EMPRF_YN">C</FLD>
<FLD NM="EPL_QF_IHHRF_YN">Y</FLD>
<FLD NM="EPL_QF_WRTGR_YN">Y</FLD>
<FLD NM="EPL_QF_WRTGD_YN">D</FLD>
<FLD NM="EPL_QF_PLPRC_YN">B</FLD>
<FLD NM="EPL_QF_REDPR_YN">N</FLD>
<FLD NM="EPL_QF_ACQMR_YN">N</FLD>
<FLD NM="EPL_QF_CLAIM_YN">D</FLD>
<FLD NM="EPL_QF_CIRCS_YN">N</FLD>
<FLD NM="EPL_RI_ACTXS">2500.00</FLD>
<FLD NM="EPL_RI_LIMIT">1000000.00</FLD>
<FLD NM="EPL_RI_UNDLT">0.00</FLD>
<FLD NM="EPL_RI_AGRGD">N</FLD>
<FLD NM="EPL_QF_NUKSB_YN">N</FLD>
</COVINPUTS>
</COVERAGE>
</COVERAGES>
</
POLICIES>

there's another xml document ( source.xml)
<POLICIES>
<COVERAGES>
<COVERAGE RBID="304106859_304106967" NAME="V02:CALCULATION">
<COVFORMULAINDEX FORMREF="EPL"/>
<COVINPUTS>
<FLD NM="EPL_RI_SGEXS" TYPE="Numeric">2500.0000</FLD>
<FLD NM="EPL_QF_NUKSB_YN" TYPE="Alphanumeric">N</FLD>
<FLD NM="EPL_RF_NUKSL" TYPE="Numeric">0.9000</FLD>
<FLD NM="EPL_RF_NWOSL" TYPE="">0.9000</FLD>
</COVINPUTS>
</COVERAGE>
<COVERAGE RBID="630ccb06-7581-451b-94ef-1b3a033a9b73" NAME="V01:CALCULATION">
<COVFORMULAINDEX FORMREF="a5750387-5417-4248-a6c1-48c05cf7396a"/>
<COVINPUTS>
<FLD NM="DAO_SQPUB_ACLGA" TYPE="Numeric" LEVEL="Coverage" SIZE="15" USE="General" SPECIFICUSE="Input" SOURCE="D"/>
<FLD NM="DAO_SQPRV_CLAIM_YN" TYPE="Alphanumeric" LEVEL="Coverage" SIZE="1" USE="General" SPECIFICUSE="Input" SOURCE="D"/>
</COVINPUTS>
</COVERAGE>
</COVERAGES>
</
POLICIES>

the resulting xml..
1.copy all the nodes in from the input xml.
2. compare the FLD's ( by matching attribut NM) if the input.xml is missing any of the COVERAGE /COVINPUTS/FLDs then copy them from source.xml
3.COVERAGE /COVFORMULAINDEX /@FORMREF should match as well


I got the following xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" exclude-result-prefixes="xsl">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:variable name="source" select="'input2.xml'"/>
<xsl:template match="/*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="COVINPUTS">
<COVINPUTS>
<xsl:apply-templates select="FLD"/><xsl:variable name="formRef" select="../COVFORMULAINDEX/@FORMREF"/>
<xsl:for-each select="document($source)//COVERAGE">
<xsl:if test="COVFORMULAINDEX/@FORMREF = $formRef">
<xsl:apply-templates select="COVINPUTS/FLD" mode="copyPolicy"/>
</xsl:if>
</xsl:for-each>
</COVINPUTS>
</xsl:template>
<xsl:template match="FLD" mode="copyPolicy">
<xsl:variable name="name" select="@NM"/>
<!-- check if a FLDnode with $name attribute exsits in the main input xml if not copy the FLD node to the output --></xsl:template>
<xsl:template match="FLD">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

could you please help me how to get this.
many thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying all the nodes except the specific node arunprasadlv XSLT 14 July 22nd, 2009 09:19 AM
copying the value of xsl in variable and comparing amhicraig XSLT 1 December 4th, 2007 07:58 PM
Problem Copying Nodes tclotworthy XSLT 14 February 13th, 2007 01:13 PM
Problem copying XML nodes francislang XSLT 9 October 21st, 2005 10:37 AM
Copying XML nodes from one document to another hughcr C# 2 May 12th, 2005 01:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.