I have the following XML file that i will transform to another XML file:
<Report> <MessageDetails> <MessageGeneratedOn>2016-01-13T17:56:22</MessageGeneratedOn> <ReportingPeriod>2016-12-31</ReportingPeriod> </MessageDetails> <Reporting1> <OrganizationName>API Guernsey Limited</OrganizationName> <DistrictName>Windsor</DistrictName> <City>Corres</City> </Reporting1> </Report> I apply the following XSLT to transform:
<?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="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> <xsl:template match="Report"> <FATCA_OECD version="1.1" schemaLocation="urn:oecd:ties:fatca:v1 FatcaXML_v1.1.xsd" > <xsl:element name ="ReportingPeriod"> <xsl:value-of select="MessageDetails/ReportingPeriod"/> </xsl:element> <xsl:element name ="Timestamp"> <xsl:value-of select="MessageDetails/MessageGeneratedOn"/> </xsl:element> <Reporting1> <xsl:element name ="Name"> <xsl:value-of select="ReportingFI/Name"/> </xsl:element> <Address> <xsl:element name ="DistrictName"> <xsl:value-of select="ReportingFI/Address2"/> </xsl:element> <xsl:element name ="City"> <xsl:value-of select="ReportingFI/City"/> </xsl:element> </Address> </Reporting1> </FATCA_OECD> </xsl:template> </xsl:stylesheet> This create the following XML:
<FATCA_OECD version="1.1" schemaLocation="urn:oecd:ties:fatca:v1 FatcaXML_v1.1.xsd"> <MessageSpec> <ReportingPeriod>2016-12-31</ReportingPeriod> <XMLTimeStamp>2016-01-13T17:56:22</XMLTimeStamp> </MessageSpec> <FATCA> <Reporting1> <Address> <DistrictName></DistrictName> <City>Corres</City> </Address> </Reporting1> <ReportingGroup /> </FATCA> </FATCA_OECD> But i need XML with namespace.How can i create XML with namespace like the following?:
ftc:FATCA_OECD version="1.1" schemaLocation="urn:oecd:ties:fatca:v1 FatcaXML_v1.1.xsd"> <ftc:MessageSpec> <sfa:ReportingPeriod>2016-12-31</sfa:ReportingPeriod> <sfa:XMLTimeStamp>2016-01-13T17:56:22</sfa:XMLTimeStamp> </ftc:MessageSpec> <ftc:FATCA> <ftc:Reporting1> <sfa:Address> <sfa:DistrictName></sfa:DistrictName> <sfa:City>Corres</sfa:City> </sfa:Address> </Reporting1> <ftc:ReportingGroup /> </ftc:FATCA> </ftc:FATCA_OECD> Thanks.
No comments:
Post a Comment