Reputation: 56
I want to create XSLT for copying same input XML but with copy of some elements from one tag to sibling tag.
Here is my input file http://pastebin.com/7hVmRcqN
I want output same as input file, except content inside following tag. <cac:Delivery>....</cac:Delivery>
Copy all elements from <cac:Delivery><cac:Address> .... </cac:Address>
and put into newly created tag inside
<cac:DeliveryParty><cac:PostalAddress> ... </cac:PostalAddress></cac:DeliveryParty>
Here <cac:DeliveryParty>
is already present in input XML..
Need to create new tag <cac:PostalAddress> ... </cac:PostalAddress>
inside <cac:DeliveryParty>... </cac:DeliveryParty>
And all tags from <cac:Delivery><cac:Address> .... </cac:Address>
will be copied inside <cac:PostalAddress> ... </cac:PostalAddress>
Tag and all its content from original input file
<cac:Delivery>
<cac:DeliveryLocation>
<cbc:Description>er</cbc:Description>
<cac:Address>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>sadasd</cbc:StreetName>
<cbc:CityName>asd</cbc:CityName>
<cbc:PostalZone>6630</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:Address>
</cac:DeliveryLocation>
<cac:DeliveryParty>
<cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>asd asd asd</cbc:Name>
</cac:PartyName>
</cac:DeliveryParty>
</cac:Delivery>
So updated <cac:Delivery>..</cac:Delivery>
tag will look like below generated..
<cac:Delivery>
<cac:DeliveryLocation>
<cbc:Description>er</cbc:Description>
<cac:Address>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>sadasd</cbc:StreetName>
<cbc:CityName>asd</cbc:CityName>
<cbc:PostalZone>6630</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:Address>
</cac:DeliveryLocation>
<cac:DeliveryParty>
<cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>asd asd asd</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>sadasd</cbc:StreetName>
<cbc:CityName>asd</cbc:CityName>
<cbc:PostalZone>6630</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
</cac:DeliveryParty>
</cac:Delivery>
Here is the xslt code that i tried to make, but do not know what to do next
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:oioubl = "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ccts = "urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2"
xmlns:sdt = "urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2"
xmlns:udt = "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2">
<!--Identity template, provides default behavior that copies all content into the output -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="cac:DeliveryParty">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="cac:PostalAddress">
</xsl:element>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Final Output of XML should look like this
<?xml version="1.0" encoding="UTF-8"?>
<!--XML file created by Microsoft Dynamics C5-->
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:un:unece:uncefact:documentation:2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<cbc:UBLVersionID schemeAgencyID="320" schemeAgencyName="urn:oioubl:id:profileid-1.1">2.0</cbc:UBLVersionID>
<cbc:CustomizationID>OIOUBL-2.02</cbc:CustomizationID>
<cbc:ProfileID schemeID="urn:oioubl:id:profileid-1.2" schemeAgencyID="320">Procurement-BilSim-1.0</cbc:ProfileID>
<cbc:ID>Test123</cbc:ID>
<cbc:IssueDate>2016-03-22</cbc:IssueDate>
<cbc:InvoiceTypeCode listID="urn:oioubl:codelist:invoicetypecode-1.1" listAgencyID="320">380</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>DKK</cbc:DocumentCurrencyCode>
<cbc:AccountingCost />
<cac:OrderReference>
<cbc:ID>Test321</cbc:ID>
<cbc:SalesOrderID>Test212</cbc:SalesOrderID>
<cbc:IssueDate>2016-03-21</cbc:IssueDate>
</cac:OrderReference>
<cac:AccountingSupplierParty>
<cac:Party>
<cbc:EndpointID schemeID="GLN" schemeAgencyID="9">9999999999999</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="DK:CVR">DK99999999</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>F & H Com. A/S</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>Tets</cbc:StreetName>
<cbc:InhouseMail>[email protected]</cbc:InhouseMail>
<cbc:CityName>test</cbc:CityName>
<cbc:PostalZone>8751</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID schemeID="DK:SE">DK99999999</cbc:CompanyID>
<cac:TaxScheme>
<cbc:ID schemeID="urn:oioubl:id:taxschemeid-1.1" schemeAgencyID="320">63</cbc:ID>
<cbc:Name>Moms</cbc:Name>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:PartyLegalEntity>
<cbc:RegistrationName>test</cbc:RegistrationName>
<cbc:CompanyID schemeID="DK:CVR">DK99999999</cbc:CompanyID>
</cac:PartyLegalEntity>
<cac:Contact>
<cbc:ID>ZZ</cbc:ID>
<cbc:Name>DK99999999</cbc:Name>
<cbc:Telephone>DK99999999</cbc:Telephone>
<cbc:Telefax>DK99999999</cbc:Telefax>
<cbc:ElectronicMail>DK99999999</cbc:ElectronicMail>
</cac:Contact>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
<cac:Party>
<cbc:EndpointID schemeID="GLN" schemeAgencyID="9">8888888888888</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="DK:CVR">DK33333333</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>zdfsdf</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>etwf</cbc:StreetName>
<cbc:CityName>asd</cbc:CityName>
<cbc:PostalZone>6500</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID schemeID="DK:SE">DK33333333</cbc:CompanyID>
<cac:TaxScheme>
<cbc:ID schemeID="urn:oioubl:id:taxschemeid-1.1" schemeAgencyID="320">63</cbc:ID>
<cbc:Name>Moms</cbc:Name>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:PartyLegalEntity>
<cbc:RegistrationName>tesad</cbc:RegistrationName>
<cbc:CompanyID schemeID="DK:CVR">DK33333333</cbc:CompanyID>
</cac:PartyLegalEntity>
<cac:Contact>
<cbc:ID>ZZ</cbc:ID>
</cac:Contact>
</cac:Party>
</cac:AccountingCustomerParty>
<cac:BuyerCustomerParty>
<cac:Party>
<cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5704707012544</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="DK:CVR">DK07012544</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>Davidsenshop.dk</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>Industrivej 36</cbc:StreetName>
<cbc:InhouseMail>[email protected]</cbc:InhouseMail>
<cbc:CityName>Vamdrup</cbc:CityName>
<cbc:PostalZone>6580</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyLegalEntity>
<cbc:RegistrationName>Davidsenshop.dk</cbc:RegistrationName>
<cbc:CompanyID schemeID="DK:CVR">DK07012544</cbc:CompanyID>
</cac:PartyLegalEntity>
<cac:Contact>
<cbc:ID>test123</cbc:ID>
<cbc:Telephone>78774800</cbc:Telephone>
<cbc:ElectronicMail>[email protected]</cbc:ElectronicMail>
</cac:Contact>
</cac:Party>
</cac:BuyerCustomerParty>
<cac:SellerSupplierParty>
<cac:Party>
<cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5790002307478</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="DK:CVR">DK28893353</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>F & H Com. A/S</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>Gl. Kattrupvej 4</cbc:StreetName>
<cbc:InhouseMail>[email protected]</cbc:InhouseMail>
<cbc:CityName>Gedved</cbc:CityName>
<cbc:PostalZone>8751</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyLegalEntity>
<cbc:RegistrationName>F & H Com. A/S</cbc:RegistrationName>
<cbc:CompanyID schemeID="DK:CVR">DK28893353</cbc:CompanyID>
</cac:PartyLegalEntity>
<cac:Contact>
<cbc:ID>ZZ</cbc:ID>
<cbc:Name>Kenneth Rix Bløcher</cbc:Name>
<cbc:Telephone>76273744</cbc:Telephone>
<cbc:Telefax>76273748</cbc:Telefax>
<cbc:ElectronicMail>[email protected]</cbc:ElectronicMail>
</cac:Contact>
</cac:Party>
</cac:SellerSupplierParty>
<cac:Delivery>
<cac:DeliveryLocation>
<cbc:Description>er</cbc:Description>
<cac:Address>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>sadasd</cbc:StreetName>
<cbc:CityName>asd</cbc:CityName>
<cbc:PostalZone>6630</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:Address>
</cac:DeliveryLocation>
<cac:DeliveryParty>
<cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>asd asd asd</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>sadasd</cbc:StreetName>
<cbc:CityName>asd</cbc:CityName>
<cbc:PostalZone>6630</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
</cac:DeliveryParty>
</cac:Delivery>
<cac:PaymentMeans>
<cbc:ID>1</cbc:ID>
<cbc:PaymentMeansCode>42</cbc:PaymentMeansCode>
<cbc:PaymentDueDate>2016-04-15</cbc:PaymentDueDate>
<cbc:PaymentChannelCode listID="urn:oioubl:codelist:paymentchannelcode-1.1" listAgencyID="320">DK:BANK</cbc:PaymentChannelCode>
<cac:PayeeFinancialAccount>
<cbc:ID>asd</cbc:ID>
<cac:FinancialInstitutionBranch>
<cbc:ID>test123</cbc:ID>
</cac:FinancialInstitutionBranch>
</cac:PayeeFinancialAccount>
</cac:PaymentMeans>
<cac:PaymentTerms>
<cbc:Note>SPECIFIC</cbc:Note>
<cbc:Amount currencyID="DKK">796.00</cbc:Amount>
</cac:PaymentTerms>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="DKK">159.20</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="DKK">636.80</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="DKK">159.20</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID schemeID="urn:oioubl:id:taxcategoryid-1.1" schemeAgencyID="320">StandardRated</cbc:ID>
<cbc:Percent>25.00</cbc:Percent>
<cac:TaxScheme>
<cbc:ID schemeID="urn:oioubl:id:taxschemeid-1.1" schemeAgencyID="320">63</cbc:ID>
<cbc:Name>Moms</cbc:Name>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:LegalMonetaryTotal>
<cbc:LineExtensionAmount currencyID="DKK">636.80</cbc:LineExtensionAmount>
<cbc:TaxExclusiveAmount currencyID="DKK">159.20</cbc:TaxExclusiveAmount>
<cbc:TaxInclusiveAmount currencyID="DKK">796.00</cbc:TaxInclusiveAmount>
<cbc:PayableAmount currencyID="DKK">796.00</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
<cac:InvoiceLine>
<cbc:ID>1</cbc:ID>
<cbc:InvoicedQuantity unitCode="EA">1.00</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="DKK">636.80</cbc:LineExtensionAmount>
<cac:OrderLineReference>
<cbc:LineID>1</cbc:LineID>
<cac:OrderReference>
<cbc:ID>test123</cbc:ID>
<cbc:SalesOrderID>19070</cbc:SalesOrderID>
</cac:OrderReference>
</cac:OrderLineReference>
<cac:Delivery>
<cbc:ActualDeliveryDate>2016-03-22</cbc:ActualDeliveryDate>
</cac:Delivery>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="DKK">159.20</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="DKK">636.80</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="DKK">159.20</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID schemeID="urn:oioubl:id:taxcategoryid-1.1" schemeAgencyID="320">StandardRated</cbc:ID>
<cbc:Percent>25.00</cbc:Percent>
<cac:TaxScheme>
<cbc:ID schemeID="urn:oioubl:id:taxschemeid-1.1" schemeAgencyID="320">63</cbc:ID>
<cbc:Name>Moms</cbc:Name>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:Item>
<cbc:Description>werwe</cbc:Description>
<cbc:Name>werwer</cbc:Name>
<cac:BuyersItemIdentification>
<cbc:ID>10017</cbc:ID>
</cac:BuyersItemIdentification>
<cac:SellersItemIdentification>
<cbc:ID>10017</cbc:ID>
</cac:SellersItemIdentification>
</cac:Item>
<cac:Price>
<cbc:PriceAmount currencyID="DKK">636.8000</cbc:PriceAmount>
<cbc:BaseQuantity unitCode="EA">1.00</cbc:BaseQuantity>
<cbc:OrderableUnitFactorRate>1</cbc:OrderableUnitFactorRate>
</cac:Price>
</cac:InvoiceLine>
</Invoice>
Any help would be appreciated
Thanks
Upvotes: 2
Views: 1710
Reputation: 56
I tried my way before answer from har07 . Following is XSLT that i tried
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:oioubl = "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ccts = "urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2"
xmlns:sdt = "urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2"
xmlns:udt = "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2">
<!--Identity template, provides default behavior that copies all content into the output -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="cac:DeliveryParty">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="cac:PostalAddress">
<xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cbc:AddressFormatCode" />
<xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cbc:StreetName" />
<xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cbc:CityName" />
<xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cbc:PostalZone" />
<xsl:copy-of select="../cac:DeliveryLocation/cac:Address/cac:Country" />
</xsl:element>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But i think the approach of har07 is much better as it will cover all tags from Input XML. And in my XSLT it will only cover the listed tags in XSLT.
So i will prefer following XSLT script from har07 is the best one.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:cac = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="cac:DeliveryParty">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="cac:PostalAddress">
<xsl:copy-of select="../cac:DeliveryLocation/cac:Address/*"/>
</xsl:element>
</xsl:copy>
</xsl:template>
<!--Identity template, provides default behavior that copies all content into the output -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Upvotes: 0
Reputation: 89285
You can use xsl:copy-of
passing XPath argument that references all child of cac:Address
in current cac:Delivery
ancestor :
<xsl:element name="cac:PostalAddress">
<xsl:copy-of select="../cac:DeliveryLocation/cac:Address/*"/>
</xsl:element>
Below is a complete working example
XML Input :
<cac:Delivery
xmlns:cac = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
>
<cac:DeliveryLocation>
<cbc:Description>er</cbc:Description>
<cac:Address>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>sadasd</cbc:StreetName>
<cbc:CityName>asd</cbc:CityName>
<cbc:PostalZone>6630</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:Address>
</cac:DeliveryLocation>
<cac:DeliveryParty>
<cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>asd asd asd</cbc:Name>
</cac:PartyName>
</cac:DeliveryParty>
</cac:Delivery>
XSLT :
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:cac = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="cac:DeliveryParty">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:element name="cac:PostalAddress">
<xsl:copy-of select="../cac:DeliveryLocation/cac:Address/*"/>
</xsl:element>
</xsl:copy>
</xsl:template>
<!--Identity template, provides default behavior that copies all content into the output -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Output :
<?xml version="1.0" encoding="UTF-8"?>
<cac:Delivery xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
<cac:DeliveryLocation>
<cbc:Description>er</cbc:Description>
<cac:Address>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>sadasd</cbc:StreetName>
<cbc:CityName>asd</cbc:CityName>
<cbc:PostalZone>6630</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:Address>
</cac:DeliveryLocation>
<cac:DeliveryParty>
<cbc:EndpointID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="GLN" schemeAgencyID="9">5555555555555</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>asd asd asd</cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:AddressFormatCode listID="urn:oioubl:codelist:addressformatcode-1.1" listAgencyID="320">StructuredLax</cbc:AddressFormatCode>
<cbc:StreetName>sadasd</cbc:StreetName>
<cbc:CityName>asd</cbc:CityName>
<cbc:PostalZone>6630</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode>DK</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
</cac:DeliveryParty>
</cac:Delivery>
Upvotes: 3