none
How to Map XML's when Input xml not does not have exact Name space RRS feed

  • Question

  • Hi Team,

    Currently i have a requirement to write xslt map to transform one xml format to another format, according to when i trying to map the xml's on the xslt, noticed input xml does not have a exact namespace, Due to the reason i'm still not able to write namespace mapping, According to Could you please support to create header mapping, for yo

    Input Sample Xml-:

    <?xml version='1.0' encoding='utf-8'?>
    <RECORDS>
    <Header>
    <MessageId>HAWB XML Export</MessageId>
    <SendingDate>2018-10-12 16:39:56</SendingDate>
    <JobType>AIR IMPORT</JobType>
    </Header>
    <RECORD>

    <Consignee>
    <ID>162</ID>
    <Name>North TECH CO.,LTD</Name>
    <Address>CENTER POWER PARK</Address>
      <Contact>
      <Name></Name>
      <Email></Email>
      <Tel></Tel>
      </Contact>
    </Consignee>
    <Shipment>
    <CargoReadyDate>0000-00-00 00:00:00</CargoReadyDate>
    <CargoHandOverDate>0000-00-00</CargoHandOverDate>
    <JobType>Direct</JobType>
    <AgentID></AgentID>
    <Airline>
    <ID>65</ID>
    <Name>AIR ASIA</Name>
    </Airline>
    <FlightNo>AU745</FlightNo>
    <APOL>SYD</APOL>

    </Shipment>
    <FlightRouteCount>2</FlightRouteCount>
    <FROUTES>

    <FROUTE>
    <FlightCode>CX</FlightCode>
    <FlightNo>611</FlightNo>
    <FlightDate>2018-10-17</FlightDate>
    <FlightTime>20:15:00</FlightTime>
    <FlightAPOL>SYD</FlightAPOL>
    <FlightAPOD>CMB</FlightAPOD>
    </FROUTE>
    </FROUTES>
    </RECORD>

    </RECORDS>


    Current Namespace mapping-:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0= 

    <xsl:template match="/">

    Output:-

         

    <UniversalShipment xmlns="http://www.cse.com/Schemas/Universal/2011/11" version="1.1">
      <Shipment>   
        <DataContext>
          <DataTargetCollection>
            <DataTarget>
              <Type>ForwardingShipment</Type>
              <Key></Key>
            </DataTarget>
          </DataTargetCollection>

          <Company>
            <Code>LK1</Code>        
          </Company>

          <EnterpriseID>EXK</EnterpriseID>
          <ServerID>TST</ServerID> 
        </DataContext>

        <ActualChargeable>1000.000</ActualChargeable>
        <AdditionalTerms></AdditionalTerms>

    etc...........

    Monday, December 30, 2019 4:38 PM

Answers

  • Hi Manesh,

    Input XML doesn't have any namespaces, though output XML has one namespace.

    It is not clear what is relationship/mapping on individual XML elements level between input and output XMLs.

    In any case, here is an XSLT to show just to deal the namespaces.

    XSLT:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
    
    	<xsl:template match="/">
    		<UniversalShipment xmlns="http://www.cse.com/Schemas/Universal/2011/11" version="1.1">
    			<Shipment>
    				<DataContext>
    					<DataTargetCollection>
    						<DataTarget>
    							<Type>ForwardingShipment</Type>
    							<Key></Key>
    						</DataTarget>
    					</DataTargetCollection>
    					<Company>
    						<Code>LK1</Code>
    					</Company>
    					<EnterpriseID>EXK</EnterpriseID>
    					<ServerID>TST</ServerID>
    				</DataContext>
    				<ActualChargeable>1000.000</ActualChargeable>
    				<AdditionalTerms></AdditionalTerms>
    			</Shipment>
    		</UniversalShipment>
    	</xsl:template>
    </xsl:stylesheet>
    • Marked as answer by Maheshma Tuesday, December 31, 2019 5:15 AM
    Monday, December 30, 2019 5:39 PM
  • Hi Manesh,

    Input XML doesn't have any namespaces, though output XML has one namespace.

    It is not clear what is relationship/mapping on individual XML elements level between input and output XMLs.

    In any case, here is an XSLT to show just to deal the namespaces.

    XSLT:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
    
    	<xsl:template match="/">
    		<UniversalShipment xmlns="http://www.cse.com/Schemas/Universal/2011/11" version="1.1">
    			<Shipment>
    				<DataContext>
    					<DataTargetCollection>
    						<DataTarget>
    							<Type>ForwardingShipment</Type>
    							<Key></Key>
    						</DataTarget>
    					</DataTargetCollection>
    					<Company>
    						<Code>LK1</Code>
    					</Company>
    					<EnterpriseID>EXK</EnterpriseID>
    					<ServerID>TST</ServerID>
    				</DataContext>
    				<ActualChargeable>1000.000</ActualChargeable>
    				<AdditionalTerms></AdditionalTerms>
    			</Shipment>
    		</UniversalShipment>
    	</xsl:template>
    </xsl:stylesheet>

    • Marked as answer by Maheshma Tuesday, December 31, 2019 5:15 AM
    Monday, December 30, 2019 5:52 PM

All replies

  • Hi Manesh,

    Input XML doesn't have any namespaces, though output XML has one namespace.

    It is not clear what is relationship/mapping on individual XML elements level between input and output XMLs.

    In any case, here is an XSLT to show just to deal the namespaces.

    XSLT:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
    
    	<xsl:template match="/">
    		<UniversalShipment xmlns="http://www.cse.com/Schemas/Universal/2011/11" version="1.1">
    			<Shipment>
    				<DataContext>
    					<DataTargetCollection>
    						<DataTarget>
    							<Type>ForwardingShipment</Type>
    							<Key></Key>
    						</DataTarget>
    					</DataTargetCollection>
    					<Company>
    						<Code>LK1</Code>
    					</Company>
    					<EnterpriseID>EXK</EnterpriseID>
    					<ServerID>TST</ServerID>
    				</DataContext>
    				<ActualChargeable>1000.000</ActualChargeable>
    				<AdditionalTerms></AdditionalTerms>
    			</Shipment>
    		</UniversalShipment>
    	</xsl:template>
    </xsl:stylesheet>
    • Marked as answer by Maheshma Tuesday, December 31, 2019 5:15 AM
    Monday, December 30, 2019 5:39 PM
  • Hi Manesh,

    Input XML doesn't have any namespaces, though output XML has one namespace.

    It is not clear what is relationship/mapping on individual XML elements level between input and output XMLs.

    In any case, here is an XSLT to show just to deal the namespaces.

    XSLT:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
    
    	<xsl:template match="/">
    		<UniversalShipment xmlns="http://www.cse.com/Schemas/Universal/2011/11" version="1.1">
    			<Shipment>
    				<DataContext>
    					<DataTargetCollection>
    						<DataTarget>
    							<Type>ForwardingShipment</Type>
    							<Key></Key>
    						</DataTarget>
    					</DataTargetCollection>
    					<Company>
    						<Code>LK1</Code>
    					</Company>
    					<EnterpriseID>EXK</EnterpriseID>
    					<ServerID>TST</ServerID>
    				</DataContext>
    				<ActualChargeable>1000.000</ActualChargeable>
    				<AdditionalTerms></AdditionalTerms>
    			</Shipment>
    		</UniversalShipment>
    	</xsl:template>
    </xsl:stylesheet>

    • Marked as answer by Maheshma Tuesday, December 31, 2019 5:15 AM
    Monday, December 30, 2019 5:52 PM
  • Hi Yitzhak,

    Thank you very much its working and thank you for your guidance.

    Thanks

    Mahesh

    Tuesday, December 31, 2019 5:17 AM