none
how to map xml data(xslt) when Element tag have xmlns RRS feed

  • Question

  • When i write a xslt map i have found input xml root element tag and other main element tag have a 'xmlns' (xml namespace) so i have  concern how to map data with this xmlns,  So could you please support to support to map that data. for your reference here with attached sample input file.

    Input Sample xml

    <?xml version="1.0" encoding="utf-8"?>
    <Root xmlns="http://IntegrationAccount1.Schema16">
      <Consol_Details xmlns="">
        <ShipmentNo>Shipement_No</ShipmentNo>
        <ConsolType>Type</ConsolType>
        <TransportMode>Transport</TransportMode>
        <ContainerMode>Container Mode</ContainerMode>
        <Load1st>1st Load</Load1st>
        <LastDisc>Last Disc</LastDisc>
      </Consol_Details>
      <Consol_Details xmlns="">
        <ShipmentNo>S10219089768</ShipmentNo>
        <ConsolType>AGT</ConsolType>
        <TransportMode>SEA</TransportMode>
        <ContainerMode>FCL</ContainerMode>
        <Load1st>LKCMB</Load1st>
        <LastDisc>USJFK</LastDisc>
      </Consol_Details>
      <Consol_Details xmlns="">
        <ShipmentNo>S10219089769</ShipmentNo>
        <ConsolType></ConsolType>
        <TransportMode></TransportMode>
        <ContainerMode></ContainerMode>
        <Load1st></Load1st>
        <LastDisc></LastDisc>
      </Consol_Details>
      </Root>

    expected output

    <UniversalShipment xmlns="http://www.wise.lk/Schemas/Universal/2011/11" version="1.1">
      <Shipment>
        <DataContext>
          <DataTargetCollection>
            <DataTarget>
              <Type>ForwardingConsol</Type>
            </DataTarget>


          </DataTargetCollection>

          <Company>
            <Code>LK1</Code>
          </Company>
          <EnterpriseID>EXK</EnterpriseID>
          <ServerID>TST</ServerID>
          
        </DataContext>

    <SubShipmentCollection>
    <SubShipment>
    <DataContext>
    <DataTargetCollection>
    <DataTarget>
    <Type>ForwardingShipment</Type>
    <Key>S10219089768</Key>
    </DataTarget>
    </DataTargetCollection>
    </DataContext>
    </SubShipment>
    </SubShipmentCollection>

        <AgentsReference></AgentsReference>
        <AWBServiceLevel>
          <Code>STD</Code>
        </AWBServiceLevel>
        
        <ContainerMode>
          <Code>FCL</Code>
        </ContainerMode>
        <FreightRateCurrency>
          <Code>LKR</Code>
        </FreightRateCurrency>
     
       
        <PaymentMethod>
          <Code>PPD</Code>
         </PaymentMethod>
     
       
        <ScreeningStatus>
          <Code>UNK</Code>
        </ScreeningStatus>

        <ShipmentType>
          <Code>AGT</Code>
        </ShipmentType>

       
        <TotalNoOfPacksPackageType>
          <Code>PKG</Code>
        </TotalNoOfPacksPackageType>
      
       
        <TransportMode>
          <Code>SEA</Code>
        </TransportMode>
       <VesselName>  HYUNDAI VOYAGER</VesselName>
        <VoyageFlightNo>SDFDFD</VoyageFlightNo>
        <WayBillNumber>YBEU2254875099</WayBillNumber>
        <WayBillType>
          <Code>MWB</Code>
          <Description>Master Waybill</Description>
        </WayBillType>

         

        <OrganizationAddressCollection>
          <OrganizationAddress>
            <AddressType>ReceivingForwarderAddress</AddressType>
            <OrganizationCode>EXPFRECMB</OrganizationCode>        
          </OrganizationAddress>
          <OrganizationAddress>
            <AddressType>ShippingLineAddress</AddressType>
            <OrganizationCode>AIRGENSDF</OrganizationCode>
           </OrganizationAddress>
          <OrganizationAddress>
            <AddressType>SendingForwarderAddress</AddressType>
            <OrganizationCode>EXPUSACMZ</OrganizationCode>        
          </OrganizationAddress>
        </OrganizationAddressCollection>


    <TransportLegCollection Content="Complete">
          <TransportLeg>
      <PortOfDischarge>
              <Code>ADALV</Code>
            </PortOfDischarge>
            <PortOfLoading>
              <Code>LKCMB</Code>
            </PortOfLoading>
          </TransportLeg>
        </TransportLegCollection>


        
      </Shipment>
    </UniversalShipment>



    • Edited by Maheshma Wednesday, August 28, 2019 12:32 PM
    Wednesday, August 28, 2019 12:16 PM

Answers

  • Hi Maheshma,

    Your input XML:

    <?xml version="1.0" encoding="utf-8"?>
    <Root xmlns="http://IntegrationAccount1.Schema16">
    	<Consol_Details xmlns="">
    		<ShipmentNo>Shipement_No</ShipmentNo>
    		<ConsolType>Type</ConsolType>
    		<TransportMode>Transport</TransportMode>
    		<ContainerMode>Container Mode</ContainerMode>
    		<Load1st>1st Load</Load1st>
    		<LastDisc>Last Disc</LastDisc>
    	</Consol_Details>
    	<Consol_Details xmlns="">
    		<ShipmentNo>S10219089768</ShipmentNo>
    		<ConsolType>AGT</ConsolType>
    		<TransportMode>SEA</TransportMode>
    		<ContainerMode>FCL</ContainerMode>
    		<Load1st>LKCMB</Load1st>
    		<LastDisc>USJFK</LastDisc>
    	</Consol_Details>
    	<Consol_Details xmlns="">
    		<ShipmentNo>S10219089769</ShipmentNo>
    		<ConsolType></ConsolType>
    		<TransportMode></TransportMode>
    		<ContainerMode></ContainerMode>
    		<Load1st></Load1st>
    		<LastDisc></LastDisc>
    	</Consol_Details>
    </Root>

    XSLT, and it is handling namespaces correctly:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://IntegrationAccount1.Schema16" 
     exclude-result-prefixes="a">
    	<xsl:output indent="yes" method="xml"/>
    
    	<xsl:template match="/">
    		<UniversalShipment xmlns="http://www.wise.lk/Schemas/Universal/2011/11" version="1.1">
    			<xsl:for-each select="a:Root/Consol_Details">
    				<row>
    					<ShipmentNo><xsl:value-of select="ShipmentNo"/></ShipmentNo>
    					<ConsolType><xsl:value-of select="ConsolType"/></ConsolType>
    					<TransportMode><xsl:value-of select="TransportMode"/></TransportMode>
    				</row>
    			</xsl:for-each>
    		</UniversalShipment>
    	</xsl:template>
    </xsl:stylesheet>

    Output:

    <?xml version="1.0" encoding="utf-8"?>
    <UniversalShipment version="1.1" xmlns="http://www.wise.lk/Schemas/Universal/2011/11">
      <row>
        <ShipmentNo>Shipement_No</ShipmentNo>
        <ConsolType>Type</ConsolType>
        <TransportMode>Transport</TransportMode>
      </row>
      <row>
        <ShipmentNo>S10219089768</ShipmentNo>
        <ConsolType>AGT</ConsolType>
        <TransportMode>SEA</TransportMode>
      </row>
      <row>
        <ShipmentNo>S10219089769</ShipmentNo>
        <ConsolType></ConsolType>
        <TransportMode></TransportMode>
      </row>
    </UniversalShipment>


    • Edited by Yitzhak Khabinsky Wednesday, August 28, 2019 2:36 PM
    • Marked as answer by Maheshma Thursday, August 29, 2019 2:50 AM
    Wednesday, August 28, 2019 2:32 PM

All replies

  • Hi Maheshma,

    Your input XML:

    <?xml version="1.0" encoding="utf-8"?>
    <Root xmlns="http://IntegrationAccount1.Schema16">
    	<Consol_Details xmlns="">
    		<ShipmentNo>Shipement_No</ShipmentNo>
    		<ConsolType>Type</ConsolType>
    		<TransportMode>Transport</TransportMode>
    		<ContainerMode>Container Mode</ContainerMode>
    		<Load1st>1st Load</Load1st>
    		<LastDisc>Last Disc</LastDisc>
    	</Consol_Details>
    	<Consol_Details xmlns="">
    		<ShipmentNo>S10219089768</ShipmentNo>
    		<ConsolType>AGT</ConsolType>
    		<TransportMode>SEA</TransportMode>
    		<ContainerMode>FCL</ContainerMode>
    		<Load1st>LKCMB</Load1st>
    		<LastDisc>USJFK</LastDisc>
    	</Consol_Details>
    	<Consol_Details xmlns="">
    		<ShipmentNo>S10219089769</ShipmentNo>
    		<ConsolType></ConsolType>
    		<TransportMode></TransportMode>
    		<ContainerMode></ContainerMode>
    		<Load1st></Load1st>
    		<LastDisc></LastDisc>
    	</Consol_Details>
    </Root>

    XSLT, and it is handling namespaces correctly:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://IntegrationAccount1.Schema16" 
     exclude-result-prefixes="a">
    	<xsl:output indent="yes" method="xml"/>
    
    	<xsl:template match="/">
    		<UniversalShipment xmlns="http://www.wise.lk/Schemas/Universal/2011/11" version="1.1">
    			<xsl:for-each select="a:Root/Consol_Details">
    				<row>
    					<ShipmentNo><xsl:value-of select="ShipmentNo"/></ShipmentNo>
    					<ConsolType><xsl:value-of select="ConsolType"/></ConsolType>
    					<TransportMode><xsl:value-of select="TransportMode"/></TransportMode>
    				</row>
    			</xsl:for-each>
    		</UniversalShipment>
    	</xsl:template>
    </xsl:stylesheet>

    Output:

    <?xml version="1.0" encoding="utf-8"?>
    <UniversalShipment version="1.1" xmlns="http://www.wise.lk/Schemas/Universal/2011/11">
      <row>
        <ShipmentNo>Shipement_No</ShipmentNo>
        <ConsolType>Type</ConsolType>
        <TransportMode>Transport</TransportMode>
      </row>
      <row>
        <ShipmentNo>S10219089768</ShipmentNo>
        <ConsolType>AGT</ConsolType>
        <TransportMode>SEA</TransportMode>
      </row>
      <row>
        <ShipmentNo>S10219089769</ShipmentNo>
        <ConsolType></ConsolType>
        <TransportMode></TransportMode>
      </row>
    </UniversalShipment>


    • Edited by Yitzhak Khabinsky Wednesday, August 28, 2019 2:36 PM
    • Marked as answer by Maheshma Thursday, August 29, 2019 2:50 AM
    Wednesday, August 28, 2019 2:32 PM
  • Thank you Yitzhak its worked
    Thursday, August 29, 2019 2:50 AM