This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Merge XML, simple but can't get it!


If anyone has a spare minute, this xsl has been an absolute nightmare.
The XSL below is supposed to process the xml by merging the information in
<Returned> back in main body, not sure if we are using the right methodology
as we are still new to XML, if anyone can point me in the right direction it
would be much appreciated!

Jason Swalwell

XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
	<xsl:template match="MergePolicy/Policy">
		<Policy>
			<xsl:apply-templates mode="copy"/>
		</Policy>
	</xsl:template>
	<xsl:template match="@*|node()" mode="copy">
		<xsl:copy>
			<xsl:apply-templates select="@*" mode="copy"/>
			<xsl:variable name="currentNode" select="name()"/>
			<xsl:variable name="descendantNode"
select="name(descendant::*)"/>
			<xsl:variable name="currentRefAttribute"
select="@ref"/>
			<xsl:variable name="descendantRefAttribute"
select="descendant::*/@ref"/>
			<xsl:choose>
				<xsl:when test="//Returned/*[name() =
$currentNode and @ref=$currentRefAttribute]/*[name() = $descendantNode]">
					<xsl:apply-templates
select="//Returned/*[name() = $currentNode and @ref=$currentRefAttribute]"
mode="add"/>
				</xsl:when>
				<xsl:when test="//Returned/*[name() =
$currentNode and @ref=$currentRefAttribute]">
					<xsl:copy-of
select="//Returned/*[name() = $currentNode and
@ref=$currentRefAttribute]/*"/>
					<xsl:apply-templates mode="copy"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates mode="copy"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="*" mode="add">
		<xsl:copy-of select="child::*"/>
	</xsl:template>
	<xsl:template match="*" mode="addnode">
		<xsl:apply-templates select="Assets" mode="addnode"/>
	</xsl:template>
</xsl:stylesheet>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<MergePolicy>
	<Policy>
		<PolicyHolder ref="PH1"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"; xsi:type="Person">
			<Address>
				<AddressHeader/>
				<Town/>
				<County/>
				<Country/>
			</Address>
			<Name>
				<Forename/>
				<Surname/>
				<Suffix/>
			</Name>
			<DateOfBirth>2001-06-08</DateOfBirth>
		</PolicyHolder>
		<Products ref="1">
			<ProductDefinitionRef name="Steve Test Household"
ref="SRTest100"/>
			<Section ref="2" name="Buildings Section"
type="InsuranceSection"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance";
xsi:type="InsuranceSection">
				<SectionDefinitionRef name="Buildings
Section Definition" ref="SDHHBUILDDEF"/>
				<AssetRef ref="5"/>
				<AssetRef ref="6"/>
				<Excess ref="3" name="Buildings Standard
Excess" type="Excess">
					<ExcessType>Standard</ExcessType>
					<Amount/>
				</Excess>
				<Excess ref="4" name="Buildings Subsidence
Excess" type="Excess">
					<ExcessType>Subsidence</ExcessType>
					<Amount/>
				</Excess>
				<SumInsured/>
			</Section>
		</Products>
		<Assets ref="5"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance";
xsi:type="PolicyHolderAsset">
			<AssetDefinitionRef name="Building Policyholder
Definition" ref="ADHHBLDPOLHLDDEF"/>
		</Assets>
		<Assets ref="6"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance";
xsi:type="BuildingAsset">
			<AssetDefinitionRef name="Building Asset Definition"
ref="ADHHBLDASTDEF"/>
		</Assets>
	</Policy>
	<Returned>
		<Assets type="BuildingAsset" name="Building Asset"
xsi:type="BuildingAsset"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"; ref="6">
			<AssetDefinitionRef ref="ADHHBLDASTDEF"
name="BuildingAsset"/>
			<NoOfBedrooms/>
			<FreeFromFlooding>false</FreeFromFlooding>
			<SignsOfSubsidence>false</SignsOfSubsidence>
			<GoodStateOfRepair>false</GoodStateOfRepair>
			<AnyStructuresAdded>false</AnyStructuresAdded>
			<HistoryOfSubsidence>false</HistoryOfSubsidence>
			<NearCliff>false</NearCliff>
			<Postcode/>
			<BuildingType>House</BuildingType>
			<WallConstruction>Brick</WallConstruction>
			<Age>From1980toDate</Age>
			<BuildingModifier>Detatched</BuildingModifier>
			<RoofConstruction>Tile</RoofConstruction>
			<Listed>No</Listed>
			<Value>
				<Denomination>
					<Name>Pounds</Name>
					<ISOCode>GBP</ISOCode>
				</Denomination>
				<Amount/>
			</Value>
			<ReplacementValue>
				<Denomination>
					<Name>Pounds</Name>
					<ISOCode>GBP</ISOCode>
				</Denomination>
				<Amount/>
			</ReplacementValue>
		</Assets>
		<Section ref="2">
			<Selected>True</Selected>
		</Section>
	</Returned>
</MergePolicy>


The information in this E-Mail is confidential and may be legally privileged. It may not represent the views of WebX Limited. It is intended solely for the addressees. Access to this E-Mail by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.  Any unauthorised recipient should advise the sender immediately of the error in transmission.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]