none
XML Document mapping structure error RRS feed

  • Question

  • Hi Team,

    Currently i have a requirement write a XSLT map for transform one xml format to on another format, According to its seems input xml have special element and i when i tring to write XSLT its getting formatting error, Could you please Support to me to complete that. for your reference here with attached sample input file and Current Xslt and expected Sample output.

    Input Sample-:

    <value odata.etag="">
    <ItemInternalId>2c11af0c-ec99-417d-849d-7db167171abc</ItemInternalId>
    <JS_UniqueConsignRef>S14019253333</JS_UniqueConsignRef>
    <JS_TransportMode>SEA</JS_TransportMode>
    <JS_RS_NKServiceLevel>STD</JS_RS_NKServiceLevel>
    <JS_SystemLastEditTimeUtc>2019-12-12T09:58:00Z</JS_SystemLastEditTimeUtc>
    <JS_INCO>FOB</JS_INCO>
    <JS_PackingMode>FCL</JS_PackingMode>

    </value>

    Current 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:output indent="yes" method="xml"/>


    <xsl:template match="/">

    <value>
        <ItemInternalId><xsl:value-of select="value/ItemInternalId"/></ItemInternalId>
        <JS_UniqueConsignRef><xsl:value-of select="value/JS_UniqueConsignRef"/></JS_UniqueConsignRef>
        <JS_IsForwardRegistered>0</JS_IsForwardRegistered>
        <JS_TransportMode><xsl:value-of select="value/JS_TransportMode"/></JS_TransportMode>

       </value> 
    </xsl:template>
    </xsl:stylesheet>

    Expected Output-

    <value odata.etag="">
    <ItemInternalId>2c11af0c-ec99-417d-849d-7db167171abc</ItemInternalId>
    <JS_UniqueConsignRef>S14019253333</JS_UniqueConsignRef>

     <JS_IsForwardRegistered>0</JS_IsForwardRegistered>

    <JS_TransportMode>SEA</JS_TransportMode>
    </value> 



    Monday, January 6, 2020 2:23 AM

Answers

  • Hi Mahesh,

    XSLT 1.0:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="xml"/>
    
    	<xsl:template match="/value">
    		<value odata.etag="">
    			<ItemInternalId>
    				<xsl:value-of select="ItemInternalId"/>
    			</ItemInternalId>
    			<JS_UniqueConsignRef>
    				<xsl:value-of select="JS_UniqueConsignRef"/>
    			</JS_UniqueConsignRef>
    			<JS_IsForwardRegistered>0</JS_IsForwardRegistered>
    			<JS_TransportMode>
    				<xsl:value-of select="JS_TransportMode"/>
    			</JS_TransportMode>
    		</value>
    	</xsl:template>
    </xsl:stylesheet>

    XSLT 3.0:

    <?xml version="1.0"?>
    <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml" indent="yes"/>
    	<xsl:mode on-no-match="shallow-copy"/>
    
    	<xsl:attribute-set name="att_root">
    		<xsl:attribute name="odata.etag"></xsl:attribute>
    	</xsl:attribute-set>2
    
    	<xsl:template match="value">
    		<xsl:copy use-attribute-sets="att_root">
    			<xsl:apply-templates select="ItemInternalId, JS_UniqueConsignRef, JS_TransportMode"/>
    			<JS_IsForwardRegistered>0</JS_IsForwardRegistered>
    		</xsl:copy>
    	</xsl:template>
    </xsl:stylesheet>


    Monday, January 6, 2020 5:12 AM

All replies

  • Hi Mahesh,

    XSLT 1.0:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="xml"/>
    
    	<xsl:template match="/value">
    		<value odata.etag="">
    			<ItemInternalId>
    				<xsl:value-of select="ItemInternalId"/>
    			</ItemInternalId>
    			<JS_UniqueConsignRef>
    				<xsl:value-of select="JS_UniqueConsignRef"/>
    			</JS_UniqueConsignRef>
    			<JS_IsForwardRegistered>0</JS_IsForwardRegistered>
    			<JS_TransportMode>
    				<xsl:value-of select="JS_TransportMode"/>
    			</JS_TransportMode>
    		</value>
    	</xsl:template>
    </xsl:stylesheet>

    XSLT 3.0:

    <?xml version="1.0"?>
    <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml" indent="yes"/>
    	<xsl:mode on-no-match="shallow-copy"/>
    
    	<xsl:attribute-set name="att_root">
    		<xsl:attribute name="odata.etag"></xsl:attribute>
    	</xsl:attribute-set>2
    
    	<xsl:template match="value">
    		<xsl:copy use-attribute-sets="att_root">
    			<xsl:apply-templates select="ItemInternalId, JS_UniqueConsignRef, JS_TransportMode"/>
    			<JS_IsForwardRegistered>0</JS_IsForwardRegistered>
    		</xsl:copy>
    	</xsl:template>
    </xsl:stylesheet>


    Monday, January 6, 2020 5:12 AM
  • HI Yitzhak,

    Thank you very much  its worked and its great to learned about XSLT 3.0 method as well.

    Thanks

    Mahesh

    Monday, January 6, 2020 3:44 PM