I want to copy the value of parentnode element into child node, as shown below. Can someone point me in the right direction on how to achieve this?
Thank you!
Here is the xml file.
<mainpart id="295928" num="1-MS15" quantity="1">
<explicitQuantity>1</explicitQuantity>
<proxy id="1E2B4D" ACADID="1E2B4E" basepart="58A67">
<singlepart id="24558D" num="1-m81" ncFile="1-m81.nc1" quantity="1">
<explicitQuantity>1</explicitQuantity>
<part id="58A67" name="C4X6.25" class="Beam" ACADID="59582" dstvName="C4X6.25">
<explicitQuantity>1</explicitQuantity>
<role key="Frame" name="FRAME"/>
<length>1727.194</length>
<paintArea>618840.532</paintArea>
<numHoles>8</numHoles>
<ObjectTopLevel>0.739</ObjectTopLevel>
<ObjectBottomLevel>-101.741</ObjectBottomLevel>
<material key="ASTM-A36" name="A36"/>
<coating key="G" name="G"/>
<commodity>FRAME</commodity>
<weight>16064.68</weight>
<exactWeight>15945.55</exactWeight>
<weightPerMeter>9301.02</weightPerMeter>
<density>7850.00</density>
<section key="AISC 14.1 C Channel##§##ChannelsC4X6.25" name="C4X6.25"/>
<sysLength>1727.194</sysLength>
<sawLength>1727.194</sawLength>
<angleX1>0.0000</angleX1>
<angleY1>0.0000</angleY1>
<angleX2>0.0000</angleX2>
<angleY2>0.0000</angleY2>
<SawCutInfo>0</SawCutInfo>
<ElementID>7400</ElementID>
</part>
</singlepart>
<singlepart id="295ADA" num="1-p3" quantity="4">
<explicitQuantity>4</explicitQuantity>
<part id="295C18" name="PL 1/4"x1 3/8"" class="Plate" ACADID="295C14" dstvName="PL 1/4"">
<explicitQuantity>1</explicitQuantity>
<role key="Plate" name="PLATE"/>
<length>85.725</length>
<paintArea>7215.343</paintArea>
<ObjectTopLevel>-7.199</ObjectTopLevel>
<ObjectBottomLevel>-93.396</ObjectBottomLevel>
<material key="ASTM-A36" name="A36"/>
<coating key="G" name="G"/>
<weight>143.81</weight>
<exactWeight>143.81</exactWeight>
<density>7850.00</density>
<thickness>6.350</thickness>
<width>35.535</width>
<area1>2884.914</area1>
<area2>2884.914</area2>
<contourLength>227.640</contourLength>
<ElementID>52306</ElementID>
<ElementID>52304</ElementID>
<ElementID>52303</ElementID>
<ElementID>52305</ElementID>
</part>
</singlepart>
</proxy>
</mainpart>
Here is my xsl, I know it is wrong, but I can't figure out how to fix it.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="mainpart" >
<xsl:variable name="mainpartmark" select="#name" />
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="part">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
<UserAttribute10>"$mainpartmark"</UserAttribute10>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here is the result I wanted, I want to add the node UserAttr10 on each end of Part node with value of num from mainpart node.
<mainpart id="295928" num="1-MS15" quantity="1">
<explicitQuantity>1</explicitQuantity>
<proxy id="1E2B4D" ACADID="1E2B4E" basepart="58A67">
<singlepart id="24558D" num="1-m81" ncFile="1-m81.nc1" quantity="1">
<explicitQuantity>1</explicitQuantity>
<part id="58A67" name="C4X6.25" class="Beam" ACADID="59582" dstvName="C4X6.25">
<explicitQuantity>1</explicitQuantity>
<role key="Frame" name="FRAME"/>
<length>1727.194</length>
<paintArea>618840.532</paintArea>
<numHoles>8</numHoles>
<ObjectTopLevel>0.739</ObjectTopLevel>
<ObjectBottomLevel>-101.741</ObjectBottomLevel>
<material key="ASTM-A36" name="A36"/>
<coating key="G" name="G"/>
<commodity>FRAME</commodity>
<weight>16064.68</weight>
<exactWeight>15945.55</exactWeight>
<weightPerMeter>9301.02</weightPerMeter>
<density>7850.00</density>
<section key="AISC 14.1 C Channel##§##ChannelsC4X6.25" name="C4X6.25"/>
<sysLength>1727.194</sysLength>
<sawLength>1727.194</sawLength>
<angleX1>0.0000</angleX1>
<angleY1>0.0000</angleY1>
<angleX2>0.0000</angleX2>
<angleY2>0.0000</angleY2>
<SawCutInfo>0</SawCutInfo>
<ElementID>7400</ElementID>
<UserAttr10>1-MS15</UserAttr10> <!--Add this line-->
</part>
</singlepart>
<singlepart id="295ADA" num="1-p3" quantity="4">
<explicitQuantity>4</explicitQuantity>
<part id="295C18" name="PL 1/4"x1 3/8"" class="Plate" ACADID="295C14" dstvName="PL 1/4"">
<explicitQuantity>1</explicitQuantity>
<role key="Plate" name="PLATE"/>
<length>85.725</length>
<paintArea>7215.343</paintArea>
<ObjectTopLevel>-7.199</ObjectTopLevel>
<ObjectBottomLevel>-93.396</ObjectBottomLevel>
<material key="ASTM-A36" name="A36"/>
<coating key="G" name="G"/>
<weight>143.81</weight>
<exactWeight>143.81</exactWeight>
<density>7850.00</density>
<thickness>6.350</thickness>
<width>35.535</width>
<area1>2884.914</area1>
<area2>2884.914</area2>
<contourLength>227.640</contourLength>
<ElementID>52306</ElementID>
<ElementID>52304</ElementID>
<ElementID>52303</ElementID>
<ElementID>52305</ElementID>
<UserAttr10>1-MS15</UserAttr10> <!--Add this line-->
</part>
</singlepart>
</proxy>
</mainpart>
As there is only one mainpart node (the root element), simply declare your variable as a global variable (a child of xsl:stylesheet)
<xsl:variable name="mainpartmark" select="/mainpart/#num" />
(You wouldn't need the template matching mainpart in this case).
Then, to use it, just do this...
<UserAttribute10>
<xsl:value-of select="/mainpart/#num" />
</UserAttribute10>
Try this XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xsi">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
</xsl:copy>
</xsl:template>
<xsl:variable name="mainpartmark" select="/mainpart/#num" />
<xsl:template match="part">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
<UserAttribute10>
<xsl:value-of select="$mainpartmark" />
</UserAttribute10>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Of course, you could also do it without the variable at all, and just do <xsl:value-of select="/mainpart/#num" /> instead.
And, if there were multiple mainpart nodes (under a single root element), you could also do <xsl:value-of select="ancestor::mainpart/#num" />
Related
I am looking for XSLT(1.0) code for below input and output XML.
In output XML, there can be any child node under C6 element. In below XML, i have put CN element but it could be any name.
Input XML -
<?xml version = "1.0" encoding = "UTF-8"?>
<root>
<input>
<c2>
<c3>
<c4>c4</c4>
</c3>
</c2>
</input>
<output>
<c5>
<c6>
<CN>
<T1></T1>
<T2></T2>
</CN>
</c6>
<c6>
<CN>
<T1></T1>
<T2></T2>
</CN>
</c6>
</c5>
</output>
</root>
Desired Output XML-
<root>
<output>
<c5>
<c6>
<!-- It could have any child node. Putting an example with CN child node name.-->
<CN>
<T1></T1>
<T2></T2>
<c3>
<c4>c4</c4>
<NewNode>current number of CN node which will be 1</NewNode>
<NewNode1>total number of C6 nodes which will be 2.</NewNode1>
</c3>
</CN>
</c6>
<c6>
<CN>
<T1></T1>
<T2></T2>
<c3>
<c4>c4</c4>
<NewNode>current number of CN node which will be 2</NewNode>
<NewNode1>total number of C6 nodes which will be 2.</NewNode1>
</c3>
</CN>
</c6>
</c5>
</output>
</root>
Thank you in advance.
Use the following stylesheet:
<?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" encoding="UTF-8" indent="yes" />
<xsl:template match="c6/*">
<xsl:copy>
<xsl:variable name="v1" select="count(../preceding-sibling::*)+1"/>
<xsl:variable name="v2" select="count(../../*)"/>
<xsl:apply-templates/>
<xsl:apply-templates select="../../../../input/c2/c3">
<xsl:with-param name="v1" select="$v1"/>
<xsl:with-param name="v2" select="$v2"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="c3">
<xsl:param name="v1"/>
<xsl:param name="v2"/>
<xsl:copy>
<xsl:apply-templates/>
<NewNode><xsl:value-of select="$v1"/></NewNode>
<NewNode1><xsl:value-of select="$v2"/></NewNode1>
</xsl:copy>
</xsl:template>
<xsl:template match="input"/>
<xsl:template match="#*|node()">
<xsl:copy><xsl:apply-templates select="#*|node()"/></xsl:copy>
</xsl:template>
</xsl:stylesheet>
I have a XML structure where the XML schema is irregular/not formatted. The structure looks like this-
<Host>
<element1>type0</element1>
<element2>Fruits</element2>
....
<elementn>Price0</elementn>
<Menu>
<NodeA>
<element1>type1</element1>
<element2>Fruits</element2>
....
<elementn>Price1</elementn>
<Menu>
<NodeB>
<element1>type2</element1>
<element2>Fruits</element2>
....
<elementn>Price2</elementn>
<Menu>
<NodeC>
<element1>type3</element1>
<element2>Fruits</element2>
....
<elementn>Price3</elementn>
<Menu>
<NodeD>
<Element1>type4</element1>
<Element2>Vegetables</Element2>
....
<Elementn>Price4</elementn>
</NodeD>
</Menu>
</NodeC>
</Menu>
</NodeB>
</Menu>
</NodeA>
<NodeE>
<element1>type5</element1>
<element2>Fruits</element2>
....
<elementn>Price5</elementn>
<Menu>
<NodeF>
<element1>type6</element1>
<element2>Vegetables</element2>
....
<elementn>Price6</elementn>
</NodeF>
</Menu>
</NodeE>
</Menu>
</Host>
Now my expected XML is as follows-
a) if <element2> == fruits in all the nodes, I need XML schema as follows. I may include or exclude the below n elements right under host -
`<element1>type0</element>
<element2>Fruits</element2>
....
<elementn>Price0</elementn>`
.Expected Result -
<Host>
<NodeA>
<element1>type1</element1>
<element2>Fruits</element2>
....
<elementn>Price1</elementn>
</NodeA>
<NodeB>
<element1>type2</element1>
<element2>Fruits</element2>
....
<elementn>Price2</elementn>
</NodeB>
<NodeC>
<element1>type3</element1>
<element2>Fruits</element2>
....
<elementn>Price3</elementn>
</NodeC>
<NodeE>
<element1>type5</element1>
<element2>Fruits</element2>
....
<elementn>Price5</elementn>
</NodeE>
</Host>
b) if <element2> == vegetables in all the nodes, I need XML schema as follows
Note: <element2> == Vegetables is always at the last node in the schema
<Host>
<NodeD>
<element1>type4</element1>
<element2>Vegetables</element2>
....
<elementn>Price4</elementn>
</NodeD>
<NodeF>
<element1>type6</element1>
<element2>Vegetables</element2>
....
<elementn>Price6</elementn>
</NodeF>
</Host>
Any help for getting the above XML formats through XSLT would be a great help.
If you want 2 separate document, you don't actually need 2 XSLTs. You can use one XSLT but with a parameter
<xsl:param name="element2" select="'Fruits'" />
(Here 'Fruits' is just the default value, should the parameter not be specified by the calling application).
You would start off by selecting the nodes which have element2 equal to the parameter (Do note XML and XSLT is case-sensitive, so element2 is not the same as Element2 in your XML, but I assumed that was a typo in your XML).
<xsl:apply-templates select="//*[element2=$element2]"/>
You would also need a template to ensure when a node is matched, it does not copy the child nodes...
<xsl:template match="*[element2]">
<xsl:copy>
<xsl:apply-templates select="*[not(*)]" />
</xsl:copy>
</xsl:template>
The other nodes would be handled by the identity template.
Try this XSLT...
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:param name="element2" select="'Fruits'" />
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates select="//*[element2=$element2]" mode="copy"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[element2]" mode="copy">
<xsl:copy>
<xsl:apply-templates select="*[not(*)]" mode="copy"/>
</xsl:copy>
</xsl:template>
<xsl:template match="#*|node()" mode="copy">
<xsl:copy>
<xsl:apply-templates select="#*|node()" mode="copy"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Note that if you were using XSLT 2.0, you could create multiple documents in one call, using xsl:for-each-group to get the distinct groups, and xsl:result-document to create a file for each.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/*">
<xsl:for-each-group select="//*[element2]" group-by="element2">
<xsl:result-document href="{current-grouping-key()}.xml" method="xml">
<Host>
<xsl:apply-templates select="current-group()" mode="copy" />
</Host>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="*[element2]" mode="copy">
<xsl:copy>
<xsl:apply-templates select="*[not(*)]" mode="copy"/>
</xsl:copy>
</xsl:template>
<xsl:template match="#*|node()" mode="copy">
<xsl:copy>
<xsl:apply-templates select="#*|node()" mode="copy" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I need your assistance with the logic to add the end tags. The structure i am looking at is . I tried with for-each or xsl:if or xsl:choose. The input XML is as below
<SuperShipNotice>
<Package packageType="P" packageLevel="1">
<PackageNumber>PWN34332</PackageNumber>
<ShipmentNumber>105909390</ShipmentNumber>
<ShipmentLineNumber>1</ShipmentLineNumber>
<PartNumber>1CH162-510</PartNumber>
<Quantity>1000</Quantity>
<SSCCNumber>00176364909402100165</SSCCNumber>
</Package>
<Package packageType="C" packageLevel="2">
<PackageNumber>CWX612432660</PackageNumber>
<ParentPackageNumber>PWN34332</ParentPackageNumber>
<ShipmentNumber>105909390</ShipmentNumber>
<ShipmentLineNumber>1</ShipmentLineNumber>
<PartNumber>1CH162-510</PartNumber>
<Quantity>25</Quantity>
<SSCCNumber>00176364909402100165</SSCCNumber>
</Package>
<Package packageType="S" packageLevel="3">
<PackageNumber>W1D2WNGL</PackageNumber>
<ParentPackageNumber>CWX612432660</ParentPackageNumber>
<ShipmentNumber>105909390</ShipmentNumber>
<ShipmentLineNumber>1</ShipmentLineNumber>
<PartNumber>1CH162-510</PartNumber>
<Quantity>1</Quantity>
<DateOfMfg>20131209</DateOfMfg>
<COO>CN</COO>
<SSCCNumber>00176364909402100165</SSCCNumber>
</Package>
<Package packageType="S" packageLevel="3">
<PackageNumber>W1D2WNGL</PackageNumber>
<ParentPackageNumber>CWX612432660</ParentPackageNumber>
<ShipmentNumber>105909390</ShipmentNumber>
<ShipmentLineNumber>1</ShipmentLineNumber>
<PartNumber>1CH162-510</PartNumber>
<Quantity>1</Quantity>
<DateOfMfg>20131209</DateOfMfg>
<COO>CN</COO>
<SSCCNumber>00176364909402100165</SSCCNumber>
</Package>
</SuperShipNotice>
Not sure if this can be of any use for you - following XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="SuperShipNotice">
<xsl:apply-templates select="//PackageNumber[parent::Package[#packageLevel='1']]" />
</xsl:template>
<xsl:template match="PackageNumber[parent::Package[#packageLevel='1']]">
<xsl:variable name="packageNumber" select="." />
<PkgLevel1>
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
<xsl:apply-templates select="//PackageNumber[parent::Package[#packageLevel='2'] and parent::Package/ParentPackageNumber = $packageNumber]" />
</PkgLevel1>
</xsl:template>
<xsl:template match="PackageNumber[parent::Package[#packageLevel='2']]">
<xsl:variable name="packageNumber" select="." />
<PkgLevel2>
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
<xsl:apply-templates select="//PackageNumber[parent::Package[#packageLevel='3'] and parent::Package/ParentPackageNumber = $packageNumber
and not(parent::Package/ParentPackageNumber = preceding::Package[#packageLevel='3']/ParentPackageNumber)]" />
</PkgLevel2>
</xsl:template>
<xsl:template match="PackageNumber[parent::Package[#packageLevel='3']]">
<PkgLevel3>
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</PkgLevel3>
</xsl:template>
</xsl:transform>
when applied to your input XML produces the output
<PkgLevel1>
<PackageNumber>PWN34332</PackageNumber>
<PkgLevel2>
<PackageNumber>CWX612432660</PackageNumber>
<PkgLevel3>
<PackageNumber>W1D2WNGL</PackageNumber>
</PkgLevel3>
</PkgLevel2>
</PkgLevel1>
The first template matching SuperShipNotice applies templates to PackageNumbers of Packages with the packageLevel value 1.
In the template matching those Packagenumbers templates are applied to all PackageNumbers with the packageLevel value 2 and the ParentPackageNumber of the current PackageNumber.
As there is a double entry for Packages with the packageLevel value 3, the second Package with the same ParentPackageNumber is omitted:
select="//PackageNumber[parent::Package[#packageLevel='3']
and parent::Package/ParentPackageNumber = $packageNumber
and not(parent::Package/ParentPackageNumber = preceding::Package[#packageLevel='3']/ParentPackageNumber)]"
In case you can adjust this to fit further requirements, you can use the saved Demo
I want to display only those orders which dont have OrderLineSource = YTR. All other should be displayed....
My Sample XML :
<Orders>
<Order>
<OrderID>34209649</OrderID>
<OrderStatus>checkout_complete</OrderStatus>
<Amount>32.93</Amount>
<OrderCreation>2014-02-08T00:00:03.00</OrderCreation>
<OrderCompletion>2014-02-08T00:00:03.00</OrderCompletion>
<CustomerGUID>303965683</CustomerGUID>
<CSMPurchaserGUID>0</CSMPurchaserGUID>
<Brand>TRFE</Brand>
<SourceECommerceSystem>Framework</SourceECommerceSystem>
<Currency>GBP</Currency>
<OrderChannel>Online</OrderChannel>
<TransactionSummary>
<TransactionID>2407065</TransactionID>
<MerchantReference>TEdV-5648-34209649</MerchantReference>
<CardCategory>Personal</CardCategory>
<CardScheme>VISA Debit</CardScheme>
<CardCountry>gbr</CardCountry>
<CardIssuer>sdfsdf sdf Bank asdf</CardIssuer>
<CardStartDate>0/0</CardStartDate>
<CardExpiryDate>2016/08</CardExpiryDate>
<Amount>32.93</Amount>
<Currency>GBP</Currency>
<CardPAN>************4585</CardPAN>
<Created>2014-02-07T23:56:48</Created>
<Updated>2014-02-08T00:00:03</Updated>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusReason>FULFILLED OK</ResponseStatusReason>
<HostedPageIdentifier>dsfasdf-ee85-4afa-bb6a-0afc6dc99896</HostedPageIdentifier>
<HostedPageURL>https://hps.datacash.com/hps/</HostedPageURL>
<PaymentStatus>Paid</PaymentStatus>
<PaymentType>Debit Card</PaymentType>
<NameOnCard>Miss L J adsf</NameOnCard>
<DataCashRef>56456456454</DataCashRef>
<MerchantID>545646</MerchantID>
<ThreeDCard>1</ThreeDCard>
<ThreeDRequested>1</ThreeDRequested>
<IPAddress>127.89.560.1</IPAddress>
</TransactionSummary>
<OrderLine>
<OrderLineID>84598837</OrderLineID>
<OrderID>34209649</OrderID>
<OrderLineLabel>GAREGSBV</OrderLineLabel>
<OrderLineSource>GHR</OrderLineSource>
<Quantity>1</Quantity>
<UnitPrice>32.93</UnitPrice>
<Total>32.93</Total>
<SKUCode>P0032</SKUCode>
<Title>Miss.</Title>
<FirstName>ertwer</FirstName>
<FamilyName>sdaf</FamilyName>
<DateOfBirth>1984-05-30</DateOfBirth>
<Email>sdfasdfa#hotmail.com</Email>
<Mobile>645646454</Mobile>
<PostChannel>0</PostChannel>
<TelephoneChannel>0</TelephoneChannel>
<EmailChannel>0</EmailChannel>
<TextAndOtherChannel>0</TextAndOtherChannel>
<BuildingNumber>27</BuildingNumber>
<AddressLine1>27</AddressLine1>
<AddressLine2>dsfasdf Road</AddressLine2>
<Town>London</Town>
<Country>sdfasdf er</Country>
<Postcode>KL7 2NS</Postcode>
<AddressValidated>1</AddressValidated>
<HKPolicy>
<PolicyNum>PP01754397</PolicyNum>
<ProductDescription>sadfsadfasdfgasdg</ProductDescription>
<CoverTypeDesc>Individual</CoverTypeDesc>
<SingleParentFamilyFlag>0</SingleParentFamilyFlag>
<PolicyTypeRefID>S</PolicyTypeRefID>
<PolicyTypeDesc>Sinasdfnce</PolicyTypeDesc>
<TierDesc>Classic</TierDesc>
<DestinationDesc>Worldwide including USA, Canada, Caribbean</DestinationDesc>
<TotalTravellers>1</TotalTravellers>
<NumOfAdults>1</NumOfAdults>
<NumOfUnder18>0</NumOfUnder18>
<PolicyStartDate>2014-02-08</PolicyStartDate>
<PolicyEndDate>2014-02-12</PolicyEndDate>
<BaseCost>32.93</BaseCost>
<Commission>11.18</Commission>
<UpsoldInd>0</UpsoldInd>
<TierRefID>C</TierRefID>
<DestinationRefID>W2</DestinationRefID>
<CoverTypeRefID>I</CoverTypeRefID>
<AONToPostPolicy>yes</AONToPostPolicy>
<SalesChannel>0011002</SalesChannel>
<WhereYouHeardOfUs>Press advertising</WhereYouHeardOfUs>
<TIPOLTraveller>
<TravellerUUID>1864-1</TravellerUUID>
<PolicyNum>PI0e31754397</PolicyNum>
<Title>Miss</Title>
<FirstName>sdfsf</FirstName>
<FamilyName>sdfsdf</FamilyName>
<DateOfBirth>1984-05-30</DateOfBirth>
<AgeBand>1864</AgeBand>
<DependentFlag>0</DependentFlag>
</TIPOLTraveller>
</TIPOLPolicy>
</OrderLine>
<OrderCustomerDetails>
<Title nil="true" />
<FirstName nil="true" />
<SecondName nil="true" />
<FamilyName nil="true" />
<DateOfBirth nil="true" />
<Email nil="true" />
<Telephone nil="true" />
<Mobile nil="true" />
<Gender nil="true" />
<PostChannel nil="true" />
<TelephoneChannel nil="true" />
<EmailChannel nil="true" />
<TextAndOtherChannel nil="true" />
<BuildingNumber>27</BuildingNumber>
<AddressLine1>27</AddressLine1>
<AddressLine2>asdfa Road</AddressLine2>
<Town>asdfasdf</Town>
<Country>United dsf</Country>
<Postcode>KH9 2NS</Postcode>
<AddressValidated>1</AddressValidated>
</OrderCustomerDetails>
</Order>
<Order>
<OrderID>34209674</OrderID>
<OrderStatus>checkout_complete</OrderStatus>
<Amount>11.13</Amount>
<OrderCreation>2014-02-08T00:08:40.00</OrderCreation>
<OrderCompletion>2014-02-08T00:08:40.00</OrderCompletion>
<CustomerGUID>303965688</CustomerGUID>
<CSMPurchaserGUID>0</CSMPurchaserGUID>
<Brand>TRFDS</Brand>
<SourceECommerceSystem>Framework</SourceECommerceSystem>
<Currency>GBP</Currency>
<OrderChannel>Online</OrderChannel>
<TransactionSummary>
<TransactionID>8115032</TransactionID>
<MerchantReference>JHF-0800-34209674</MerchantReference>
<CardCategory>Personal</CardCategory>
<CardScheme>VISA Debit</CardScheme>
<CardCountry>gbr</CardCountry>
<CardIssuer>Unknown</CardIssuer>
<CardStartDate>0/0</CardStartDate>
<CardExpiryDate>2016/09</CardExpiryDate>
<Amount>11.13</Amount>
<Currency>GBP</Currency>
<CardPAN>************4849</CardPAN>
<Created>2014-02-08T00:08:00</Created>
<Updated>2014-02-08T00:08:40</Updated>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusReason>FULFILLED OK</ResponseStatusReason>
<HostedPageIdentifier>f3306487-d6ea-4200-9eea-99b1d6832a2e</HostedPageIdentifier>
<HostedPageURL>https://hps.dat.com/hps/</HostedPageURL>
<PaymentStatus>Paid</PaymentStatus>
<PaymentType>Debit Card</PaymentType>
<NameOnCard>Miss Jor </NameOnCard>
<DataCashRef>380010093738013</DataCashRef>
<MerchantID>21877049</MerchantID>
<ThreeDCard>1</ThreeDCard>
<ThreeDRequested>1</ThreeDRequested>
<IPAddress>86..25640.99</IPAddress>
</TransactionSummary>
<OrderLine>
<OrderLineID>84598874</OrderLineID>
<OrderID>34209674</OrderID>
<OrderLineLabel>3-1008617753325</OrderLineLabel>
<OrderLineSource>YTR</OrderLineSource>
<Quantity>1</Quantity>
<UnitPrice>11.13</UnitPrice>
<Total>11.13</Total>
<Title>Miss.</Title>
<FirstName>Jordan</FirstName>
<SecondName>oirut</SecondName>
<FamilyName>dfgsdfgs</FamilyName>
<Email>dfgsdfg#hotmail.com</Email>
<Mobile>654756464</Mobile>
<PostChannel>0</PostChannel>
<TelephoneChannel>0</TelephoneChannel>
<EmailChannel>0</EmailChannel>
<TextAndOtherChannel>0</TextAndOtherChannel>
<BuildingNumber>12</BuildingNumber>
<AddressLine1>12</AddressLine1>
<AddressLine2>sfgsdfg End Gardens</AddressLine2>
<Town>HEMEL sfgaefa</Town>
<Country>adf dgfsdfg</Country>
<Postcode>HP1 1SN</Postcode>
<OrderLineDetail>
<NameValuePair>
<Name>dfgsdfg</Name>
<Value>628</Value>
</NameValuePair>
<NameValuePair>
<Name>NameOnCard</Name>
<Value>adsfgasdgf Piper</Value>
</NameValuePair>
<NameValuePair>
<Name>DateOnCard</Name>
<Value>2014-02-05</Value>
</NameValuePair>
<NameValuePair>
<Name>CustomsOrSurcharge</Name>
<Value>CUSTOMS CHARGE TO PAY</Value>
</NameValuePair>
</OrderLineDetail>
</OrderLine>
<OrderCustomerDetails>
<Title>Miss.</Title>
<FirstName>Jordan</FirstName>
<SecondName>asdgfasdgf</SecondName>
<FamilyName nil="true" />
<DateOfBirth />
<Email>adfadf#hotmail.com</Email>
<Telephone />
<Mobile>adfasdf</Mobile>
<Gender nil="true" />
<PostChannel nil="true" />
<TelephoneChannel nil="true" />
<EmailChannel nil="true" />
<TextAndOtherChannel nil="true" />
<BuildingNumber>12</BuildingNumber>
<AddressLine1>12</AddressLine1>
<AddressLine2>adfasdf End Gardens</AddressLine2>
<Town>adsfasdf HEMPSTEAD</Town>
<Country>United asdfasdf</Country>
<Postcode>asd 1SN</Postcode>
</OrderCustomerDetails>
</Order>
</Orders>
I tried using XSLT :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<!-- Orders -->
<xsl:template match="/*">
<xsl:element name="Orders">
<xsl:apply-templates select="./Order" />
</xsl:element>
</xsl:template>
<!-- Orders > Order -->
<xsl:template match="/Order">
<xsl:variable name="IsValid">
<xsl:call-template name="HasOrIsValidPOLine" />
</xsl:variable>
<xsl:if test="$IsValid='VALID'"> <!-- only display the order if there's a valid line under it-->
<xsl:element name="Order">
<xsl:apply-templates select=".//VORNR" />
</xsl:element>
</xsl:if>
</xsl:template>
<!-- Part Order List > Part Order > Operational BO Number -->
<xsl:template match="//VORNR">
<xsl:element name="./Order">
<xsl:apply-templates select="node()|#*"/>
<xsl:value-of select="text()"/>
</xsl:element>
</xsl:template>
<xsl:template name="HasOrIsValidPOLine">
<xsl:choose>
<xsl:when test="./OrderLineSource/text() != 'YTR'">VALID</xsl:when>
<xsl:otherwise>INVALID</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Can you provide me the solution or let me know where I am going wrong
First, your sample XML is not well-formed: It contains a closing </TIPOLPolicy> tag that doesn't match the starting <HKPolicy> tag. Change that to </HKPolicy> first.
After that, the following XSLT 1.0 does what you want:
<?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"/>
<!-- Identity transform -->
<!-- Default priority 0 for root node and -0.5 for the rest -->
<xsl:template match="/ | node() | #*">
<xsl:copy>
<xsl:apply-templates select="node() | #*"/>
</xsl:copy>
</xsl:template>
<!-- Do nothing for Order elements whose OrderLine/OrderLineSource equals 'YTR' -->
<!-- Default priority 0.5 -->
<xsl:template match="Order[OrderLine/OrderLineSource = 'YTR']"/>
</xsl:stylesheet>
It makes use of the identity transform and different default priorities: The identity transform with a lower default priority copies the input to the output unless another template with a higher priority exists for a given input match. This is the case for Order elements whose OrderLine/OrderLineSource descendant contains the text value 'YTR'. Due to its higher default priority, the more specific template takes precedence over the identity transform. Since the template doesn't produce any output, any matching Order elements are removed from the output.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Order[OrderLine/OrderLineSource[string() = 'YTR']]"/>
</xsl:stylesheet>
I am trying to rename/remove the namespace prefix from the output XML.
However, one of the top element should contain the namespace declaration without prefix.
The XSLT is not working properly. In some instances I can still see the namespace prefix in the output XML and the namespace doesn't show up in the element I want to see.
I've tried to use the exclude-result-prefixes and some templates but not working properly.
Just to clarify I'm using XSLT 1.0
Thanks in Advance ...
XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:ns0="http://somenamespace"
xmlns:ac="http://ac.namespace"
exclude-result-prefixes="ns0 msxsl ac">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" encoding="utf-8"/>
<xsl:template match="node() | #*">
<xsl:copy>
<xsl:apply-templates select="node() | #*" />
</xsl:copy>
</xsl:template>
<xsl:template match="node()|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="#*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="#*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<!--<xsl:template match="#*[local-name(.)='ns0']"/>-->
<xsl:template match="ns0:Cedent/ns0:Party/ns0:Id[. = '']">
<xsl:copy>
<xsl:apply-templates select="#*" />
<xsl:apply-templates select="../../following-sibling::ns0:Broker[1]/ns0:Party/ns0:Id/node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="ns0:Cedent/ns0:Party/ns0:Id/#Agency[. = '']">
<xsl:attribute name="Agency">DUNS_dun_and_bradstreet</xsl:attribute>
</xsl:template>
<xsl:template match="ns0:Reinsurer[not(ns0:Party/ns0:Id and ns0:Party/ns0:Id/#Agency)]" />
<xsl:template match="ns0:Reinsurer/ns0:Contact[not(ns0:PersonName)]" />
<xsl:template match="ns0:Reinsurer/ns0:Contact/*[not(node())]" />
<xsl:template match="ns0:Broker/ns0:Contact/ns0:Telephone[.='']" />
<xsl:template match="ns0:ServiceProvider[. = '6']" />
<xsl:template match="ns0:ServiceProvider[not(ns0:Party/ns0:Id and ns0:Party/ns0:Id/#Agency)]" />
<xsl:template match="ns0:Contract/ns0:ContractGroupName[not(node())]" />
<xsl:template match="ns0:Endorsement[ns0:Placing/ns0:PlacingStage = 'endorsement']" />
<xsl:template match="ns0:Endorsement/ns0:EndorsementReference[not(node())]" />
<xsl:template match="ns0:Endorsement/ns0:EndorsementName[not(node())]" />
<xsl:template match="ns0:Endorsement/ns0:Description[not(node())]" />
<xsl:template match="ns0:Endorsement/ns0:EffectiveDate[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:BrokerSharePercentage[not(node()) and ns0:ContractSection/ns0:BrokerSharePercentage/ns0:Rate > 0]" />
<xsl:template match="ns0:ContractSection/ns0:RiskLocation[not(node()) or (ns0:PlacingTransactionFunction = 'request_for_line_or_binder' or ns0:PlacingTransactionFunction = 'signed_line_advice' or ns0:PlacingTransactionFunction = 'quotation_request' or ns0:PlacingTransactionFunction = 'endorsement_request')]" />
<xsl:template match="ns0:ContractSection/ns0:RiskLocation/ns0:Location/ns0:Supraentity[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:RiskLocation/ns0:Location/ns0:Country[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:PerilsIncluded[not(ns0:Peril/ns0:PerilType !='')]" />
<xsl:template match="ns0:OrderPercentage">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
<ns0:LinesPercentageOfOrderIndicator>
<xsl:value-of select="ancestor::ns0:Placing/ns0:PlacingTransactionFunction = 'signed_line_advice' and ns0:Rate > 100"/>
</ns0:LinesPercentageOfOrderIndicator>
</xsl:template>
<xsl:template match="ns0:ContractSection/ns0:Brokerage[descendant::ns0:Rate = '' and not(ns0:ContractSection/ns0:BrokeragePercentage/ns0:Rate > 0)]" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:Reinsurer[descendant::ns0:Id = '' and not(ns0:Party/ns0:Id/#Agency[. != ''])]" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:ReinsurerContractReference[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:ReinsurerQuoteMaximumSharePercentage[descendant::ns0:Rate = '']" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:ReinsurerWrittenPercentage[descendant::ns0:Rate = '' and ns0:PlacingTransactionFunction = 'signed_line_advice']" />
</xsl:stylesheet>
Sample Input:
<ns0:Root xmlns:ns0="http://somenamespace">
<ns0:Placing Sender="broker" Receiver="serviceprovider">
<ns0:UUId>GUID</ns0:UUId>
<ns0:BrokerReference>2B3B8992-3185-48EE-A030-0F61EFF7C7EB</ns0:BrokerReference>
<ns0:ServiceProviderReference>16</ns0:ServiceProviderReference>
<ns0:PlacingStage>order</ns0:PlacingStage>
<ns0:PlacingTransactionFunction>signed_line_advice</ns0:PlacingTransactionFunction>
<ns0:TransactionReasonDescription></ns0:TransactionReasonDescription>
<ns0:Cedent>
<ns0:Party>
<ns0:Id Agency=""></ns0:Id>
<ns0:Name>Bahamas First General Insurance Co/Aon Benfield Canada</ns0:Name>
</ns0:Party>
</ns0:Cedent>
<ns0:Reinsurer>
<ns0:Party>
<ns0:Id Agency=""></ns0:Id>
<ns0:Name>RI3K</ns0:Name>
</ns0:Party>
<ns0:Contact>
<ns0:PersonName>test</ns0:PersonName>
<ns0:Telephone></ns0:Telephone>
<ns0:Email>test#ri3k.com</ns0:Email>
</ns0:Contact>
</ns0:Reinsurer>
<ns0:Broker>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">292320710</ns0:Id>
<ns0:Name>Aon Benfield UK</ns0:Name>
</ns0:Party>
<ns0:Contact>
<ns0:PersonName>Jenny Edwards</ns0:PersonName>
<ns0:Telephone>reinsurance_contract</ns0:Telephone>
<ns0:Email>jenny.edwards#aonbenfield.com</ns0:Email>
</ns0:Contact>
</ns0:Broker>
<ns0:ServiceProvider>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">239195295</ns0:Id>
</ns0:Party>
</ns0:ServiceProvider>
<ns0:Contract>
<ns0:ContractName>FINCO QUOTA SHARE TREATY</ns0:ContractName>
<ns0:ContractGroupName>BFG FINCO QUOTA SHARE TREATY</ns0:ContractGroupName>
<ns0:ContractType>0</ns0:ContractType>
<ns0:BrokerReference>B110813BDO1053</ns0:BrokerReference>
<ns0:BrokerGroupReference>200153436</ns0:BrokerGroupReference>
<ns0:BrokerRiskReference>13BDO1053</ns0:BrokerRiskReference>
</ns0:Contract>
<ns0:Endorsement>
<ns0:EndorsementReference>0</ns0:EndorsementReference>
<ns0:EndorsementName></ns0:EndorsementName>
<ns0:Description></ns0:Description>
<ns0:EffectiveDate></ns0:EffectiveDate>
</ns0:Endorsement>
<ns0:ContractSection ContractReportingLevel="section_level">
<ns0:HighLevelReference>01</ns0:HighLevelReference>
<ns0:CoverType>quota_share</ns0:CoverType>
<ns0:ContractPeriod>
<ns0:StartDate DateIndicator="Jan 1 2013 12:00AM"></ns0:StartDate>
<ns0:EndDate DateIndicator="Dec 31 2013 12:00AM"></ns0:EndDate>
</ns0:ContractPeriod>
<ns0:UnderwritingYear>Jan </ns0:UnderwritingYear>
<ns0:ContractSectionClass>
<ns0:JvClassOfBusiness>wind_storm_unspecified</ns0:JvClassOfBusiness>
<ns0:ClassOfBusinessDescription>wind_storm_unspecified</ns0:ClassOfBusinessDescription>
</ns0:ContractSectionClass>
<ns0:RiskLocation>
<ns0:Address>
<ns0:Country></ns0:Country>
</ns0:Address>
<ns0:Location>
<ns0:Supraentity></ns0:Supraentity>
<ns0:Country>BS</ns0:Country>
</ns0:Location>
</ns0:RiskLocation>
<ns0:PerilsIncluded>
<ns0:Peril>
<ns0:PerilType></ns0:PerilType>
</ns0:Peril>
</ns0:PerilsIncluded>
<ns0:ContractAmountsCurrency>
<ns0:Ccy>GBP</ns0:Ccy>
</ns0:ContractAmountsCurrency>
<ns0:BrokerSharePercentage>
<ns0:Rate RateUnit="percentage">2.500000</ns0:Rate>
</ns0:BrokerSharePercentage>
<ns0:OrderPercentage>
<ns0:Rate RateUnit="percentage">41.000000</ns0:Rate>
</ns0:OrderPercentage>
<ns0:Brokerage>
<ns0:BrokeragePercentage>
<ns0:Rate RateUnit="percentage">2.500000</ns0:Rate>
</ns0:BrokeragePercentage>
</ns0:Brokerage>
<ns0:ContractMarket>
<ns0:Reinsurer>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">239195295</ns0:Id>
</ns0:Party>
</ns0:Reinsurer>
<ns0:ParticipantFunction>leader</ns0:ParticipantFunction>
<ns0:ReinsurerContractReference></ns0:ReinsurerContractReference>
<ns0:ReinsurerQuoteMaximumSharePercentage>
<ns0:Rate RateUnit="percentage">100.000000</ns0:Rate>
</ns0:ReinsurerQuoteMaximumSharePercentage>
<ns0:ReinsurerWrittenPercentage>
<ns0:Rate RateUnit="percentage">100.000000</ns0:Rate>
</ns0:ReinsurerWrittenPercentage>
</ns0:ContractMarket>
</ns0:ContractSection>
</ns0:Placing>
</ns0:Root>
Expected OutPut:
<Root xmlns="http://somenamespace" xmlns="http://ac.namespace">
<Placing xmlns="http://somenamespace" Sender="broker" Receiver="serviceprovider">
<UUId>GUID</UUId>
<BrokerReference>2B3B8992-3185-48EE-A030-0F61EFF7C7EB</BrokerReference>
<ServiceProviderReference>16</ServiceProviderReference>
<PlacingStage>order</PlacingStage>
<PlacingTransactionFunction>signed_line_advice</PlacingTransactionFunction>
<TransactionReasonDescription />
<Cedent>
<Party>
<Id Agency="DUNS_dun_and_bradstreet" >292320710</Id>
<Name>Bahamas First General Insurance Co/Aon Benfield Canada</Name>
</Party>
</Cedent>
<Reinsurer>
<Party>
<Id Agency="" />
<Name>RI3K</Name>
</Party>
<Contact>
<PersonName>test</PersonName>
<Email>test#ri3k.com</Email>
</Contact>
</Reinsurer>
<Broker>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">292320710</Id>
<Name>Aon Benfield UK</Name>
</Party>
<Contact>
<PersonName>Jenny Edwards</PersonName>
<Telephone>reinsurance_contract</Telephone>
<Email>jenny.edwards#aonbenfield.com</Email>
</Contact>
</Broker>
<ServiceProvider>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">239195295</Id>
</Party>
</ServiceProvider>
<Contract>
<ContractName>FINCO QUOTA SHARE TREATY</ContractName>
<ContractGroupName>BFG FINCO QUOTA SHARE TREATY</ContractGroupName>
<ContractType>0</ContractType>
<BrokerReference>B110813BDO1053</BrokerReference>
<BrokerGroupReference>200153436</BrokerGroupReference>
<BrokerRiskReference>13BDO1053</BrokerRiskReference>
</Contract>
<Endorsement>
<EndorsementReference>0</EndorsementReference>
</Endorsement>
<ContractSection ContractReportingLevel="section_level">
<HighLevelReference>01</HighLevelReference>
<CoverType>quota_share</CoverType>
<ContractPeriod>
<StartDate DateIndicator="Jan 1 2013 12:00AM" />
<EndDate DateIndicator="Dec 31 2013 12:00AM" />
</ContractPeriod>
<UnderwritingYear>Jan </UnderwritingYear>
<ContractSectionClass>
<JvClassOfBusiness>wind_storm_unspecified</JvClassOfBusiness>
<ClassOfBusinessDescription>wind_storm_unspecified</ClassOfBusinessDescription>
</ContractSectionClass>
<RiskLocation>
<Address>
<Country />
</Address>
<Location>
<Country>BS</Country>
</Location>
</RiskLocation>
<ContractAmountsCurrency>
<Ccy>GBP</Ccy>
</ContractAmountsCurrency>
<BrokerSharePercentage>
<Rate RateUnit="percentage">2.500000</Rate>
</BrokerSharePercentage>
<OrderPercentage >
<Rate RateUnit="percentage">41.000000</Rate>
</OrderPercentage>
<LinesPercentageOfOrderIndicator>false</LinesPercentageOfOrderIndicator>
<Brokerage>
<BrokeragePercentage>
<Rate RateUnit="percentage">2.500000</Rate>
</BrokeragePercentage>
</Brokerage>
<ContractMarket>
<Reinsurer>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">239195295</Id>
</Party>
</Reinsurer>
<ParticipantFunction>leader</ParticipantFunction>
<ReinsurerQuoteMaximumSharePercentage>
<Rate RateUnit="percentage">100.000000</Rate>
</ReinsurerQuoteMaximumSharePercentage>
<ReinsurerWrittenPercentage>
<Rate RateUnit="percentage">100.000000</Rate>
</ReinsurerWrittenPercentage>
</ContractMarket>
</ContractSection>
</Placing>
</Root>
This XSLT does what I think you are actually trying to do (i.e. keep everything in its original namespace, and not exclude Root from it):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:ns0="http://somenamespace"
xmlns="http://somenamespace"
xmlns:ac="http://ac.namespace"
exclude-result-prefixes="ns0 msxsl ac">
<xsl:strip-space elements="*" />
<xsl:output method="xml" indent="yes"
omit-xml-declaration="yes" encoding="utf-8"/>
<xsl:template match="node() | #*">
<xsl:copy>
<xsl:apply-templates select="node() | #*" />
</xsl:copy>
</xsl:template>
<xsl:template match="node()" priority="-2">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*" name="CopyElement">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:apply-templates select="#*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="#*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<!--<xsl:template match="#*[local-name(.)='ns0']"/>-->
<xsl:template match="ns0:Cedent/ns0:Party/ns0:Id[. = '']">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:apply-templates select="#*" />
<xsl:apply-templates
select="../../following-sibling::ns0:Broker[1]/ns0:Party/ns0:Id/node()" />
</xsl:element>
</xsl:template>
<xsl:template match="ns0:Cedent/ns0:Party/ns0:Id/#Agency[. = '']">
<xsl:attribute name="Agency">DUNS_dun_and_bradstreet</xsl:attribute>
</xsl:template>
<xsl:template match="ns0:Reinsurer[not(ns0:Party/ns0:Id and ns0:Party/ns0:Id/#Agency)]" />
<xsl:template match="ns0:Reinsurer/ns0:Contact[not(ns0:PersonName)]" />
<xsl:template match="ns0:Reinsurer/ns0:Contact/*[not(node())]" />
<xsl:template match="ns0:Broker/ns0:Contact/ns0:Telephone[.='']" />
<xsl:template match="ns0:ServiceProvider[. = '6']" />
<xsl:template match="ns0:ServiceProvider[not(ns0:Party/ns0:Id and ns0:Party/ns0:Id/#Agency)]" />
<xsl:template match="ns0:Contract/ns0:ContractGroupName[not(node())]" />
<xsl:template match="ns0:Endorsement[ns0:Placing/ns0:PlacingStage = 'endorsement']" />
<xsl:template match="ns0:Endorsement/ns0:EndorsementReference[not(node())]" />
<xsl:template match="ns0:Endorsement/ns0:EndorsementName[not(node())]" />
<xsl:template match="ns0:Endorsement/ns0:Description[not(node())]" />
<xsl:template match="ns0:Endorsement/ns0:EffectiveDate[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:BrokerSharePercentage[not(node()) and ns0:ContractSection/ns0:BrokerSharePercentage/ns0:Rate > 0]" />
<xsl:template match="ns0:ContractSection/ns0:RiskLocation[not(node()) or (ns0:PlacingTransactionFunction = 'request_for_line_or_binder' or ns0:PlacingTransactionFunction = 'signed_line_advice' or ns0:PlacingTransactionFunction = 'quotation_request' or ns0:PlacingTransactionFunction = 'endorsement_request')]" />
<xsl:template match="ns0:ContractSection/ns0:RiskLocation/ns0:Location/ns0:Supraentity[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:RiskLocation/ns0:Location/ns0:Country[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:PerilsIncluded[not(ns0:Peril/ns0:PerilType !='')]" />
<xsl:template match="ns0:OrderPercentage">
<xsl:call-template name="CopyElement" />
<LinesPercentageOfOrderIndicator>
<xsl:value-of select="ancestor::ns0:Placing/ns0:PlacingTransactionFunction = 'signed_line_advice' and ns0:Rate > 100"/>
</LinesPercentageOfOrderIndicator>
</xsl:template>
<xsl:template match="ns0:ContractSection/ns0:Brokerage[descendant::ns0:Rate = '' and not(ns0:ContractSection/ns0:BrokeragePercentage/ns0:Rate > 0)]" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:Reinsurer[descendant::ns0:Id = '' and not(ns0:Party/ns0:Id/#Agency[. != ''])]" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:ReinsurerContractReference[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:ReinsurerQuoteMaximumSharePercentage[descendant::ns0:Rate = '']" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:ReinsurerWrittenPercentage[descendant::ns0:Rate = '' and ns0:PlacingTransactionFunction = 'signed_line_advice']" />
</xsl:stylesheet>
When run on your sample input, the result is:
<Root xmlns="http://somenamespace">
<Placing Sender="broker" Receiver="serviceprovider">
<UUId>GUID</UUId>
<BrokerReference>2B3B8992-3185-48EE-A030-0F61EFF7C7EB</BrokerReference>
<ServiceProviderReference>16</ServiceProviderReference>
<PlacingStage>order</PlacingStage>
<PlacingTransactionFunction>signed_line_advice</PlacingTransactionFunction>
<TransactionReasonDescription />
<Cedent>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">292320710</Id>
<Name>Bahamas First General Insurance Co/Aon Benfield Canada</Name>
</Party>
</Cedent>
<Reinsurer>
<Party>
<Id Agency="" />
<Name>RI3K</Name>
</Party>
<Contact>
<PersonName>test</PersonName>
<Email>test#ri3k.com</Email>
</Contact>
</Reinsurer>
<Broker>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">292320710</Id>
<Name>Aon Benfield UK</Name>
</Party>
<Contact>
<PersonName>Jenny Edwards</PersonName>
<Telephone>reinsurance_contract</Telephone>
<Email>jenny.edwards#aonbenfield.com</Email>
</Contact>
</Broker>
<ServiceProvider>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">239195295</Id>
</Party>
</ServiceProvider>
<Contract>
<ContractName>FINCO QUOTA SHARE TREATY</ContractName>
<ContractGroupName>BFG FINCO QUOTA SHARE TREATY</ContractGroupName>
<ContractType>0</ContractType>
<BrokerReference>B110813BDO1053</BrokerReference>
<BrokerGroupReference>200153436</BrokerGroupReference>
<BrokerRiskReference>13BDO1053</BrokerRiskReference>
</Contract>
<Endorsement>
<EndorsementReference>0</EndorsementReference>
</Endorsement>
<ContractSection ContractReportingLevel="section_level">
<HighLevelReference>01</HighLevelReference>
<CoverType>quota_share</CoverType>
<ContractPeriod>
<StartDate DateIndicator="Jan 1 2013 12:00AM" />
<EndDate DateIndicator="Dec 31 2013 12:00AM" />
</ContractPeriod>
<UnderwritingYear>Jan </UnderwritingYear>
<ContractSectionClass>
<JvClassOfBusiness>wind_storm_unspecified</JvClassOfBusiness>
<ClassOfBusinessDescription>wind_storm_unspecified</ClassOfBusinessDescription>
</ContractSectionClass>
<RiskLocation>
<Address>
<Country />
</Address>
<Location>
<Country>BS</Country>
</Location>
</RiskLocation>
<ContractAmountsCurrency>
<Ccy>GBP</Ccy>
</ContractAmountsCurrency>
<BrokerSharePercentage>
<Rate RateUnit="percentage">2.500000</Rate>
</BrokerSharePercentage>
<OrderPercentage>
<Rate RateUnit="percentage">41.000000</Rate>
</OrderPercentage>
<LinesPercentageOfOrderIndicator>false</LinesPercentageOfOrderIndicator>
<Brokerage>
<BrokeragePercentage>
<Rate RateUnit="percentage">2.500000</Rate>
</BrokeragePercentage>
</Brokerage>
<ContractMarket>
<Reinsurer>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">239195295</Id>
</Party>
</Reinsurer>
<ParticipantFunction>leader</ParticipantFunction>
<ReinsurerQuoteMaximumSharePercentage>
<Rate RateUnit="percentage">100.000000</Rate>
</ReinsurerQuoteMaximumSharePercentage>
<ReinsurerWrittenPercentage>
<Rate RateUnit="percentage">100.000000</Rate>
</ReinsurerWrittenPercentage>
</ContractMarket>
</ContractSection>
</Placing>
</Root>
Please tell me if you did actually want to exclude Root from the namespace.