none
Date Format change on XSLT RRS feed

  • Question

  • Hi Team, 

    Currently i have a  requirement to convert to  datetime format on the xslt level, Could you please support to sort out my concern,

    Current mapping output-

    <LocalProcessing>
    <DeliveryRequiredBy>20191021</DeliveryRequiredBy>
    </LocalProcessing>

    Required format-:

    <LocalProcessing>
    <DeliveryRequiredBy>2019-10-21T00:00:00.00</DeliveryRequiredBy>
    </LocalProcessing>

    Monday, October 7, 2019 12:33 PM

Answers

  • Hi Maheshma,

    Here it is. Please pay attention to the Microsoft specific namespaces declarations at the top.

    It allows to use Date/Time formatting functions.

    Input XML:

    <?xml version="1.0"?>
    <LocalProcessing>
    	<DeliveryRequiredBy>20191021</DeliveryRequiredBy>
    </LocalProcessing>


    XSLT:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:dt="urn:schemas-microsoft-com:datatypes">
    	<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
    
    	<xsl:template match="/LocalProcessing">
    		<LocalProcessing>
    			<DeliveryRequiredBy>
    				<xsl:value-of select="concat(ms:format-date(concat(substring(DeliveryRequiredBy,1,4),'-', substring(DeliveryRequiredBy,5,2), '-', substring(DeliveryRequiredBy,7,2)), 'yyyy-MM-dd'),'T00:00:00.00')"/>
    			</DeliveryRequiredBy>
    		</LocalProcessing>
    	</xsl:template>
    </xsl:stylesheet>

    Output XML:

    <LocalProcessing xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:dt="urn:schemas-microsoft-com:datatypes">
      <DeliveryRequiredBy>2019-10-21T00:00:00.00</DeliveryRequiredBy>
    </LocalProcessing>

    Please use the following line for your real XML:

    <xsl:value-of select="concat(ms:format-date(concat(substring(.,1,4),'-', substring(.,5,2), '-', substring(.,7,2)), 'yyyy-MM-dd'),'T00:00:00.00')"/>


    Monday, October 7, 2019 12:59 PM

All replies

  • Hi Maheshma,

    Here it is. Please pay attention to the Microsoft specific namespaces declarations at the top.

    It allows to use Date/Time formatting functions.

    Input XML:

    <?xml version="1.0"?>
    <LocalProcessing>
    	<DeliveryRequiredBy>20191021</DeliveryRequiredBy>
    </LocalProcessing>


    XSLT:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:dt="urn:schemas-microsoft-com:datatypes">
    	<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
    
    	<xsl:template match="/LocalProcessing">
    		<LocalProcessing>
    			<DeliveryRequiredBy>
    				<xsl:value-of select="concat(ms:format-date(concat(substring(DeliveryRequiredBy,1,4),'-', substring(DeliveryRequiredBy,5,2), '-', substring(DeliveryRequiredBy,7,2)), 'yyyy-MM-dd'),'T00:00:00.00')"/>
    			</DeliveryRequiredBy>
    		</LocalProcessing>
    	</xsl:template>
    </xsl:stylesheet>

    Output XML:

    <LocalProcessing xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:dt="urn:schemas-microsoft-com:datatypes">
      <DeliveryRequiredBy>2019-10-21T00:00:00.00</DeliveryRequiredBy>
    </LocalProcessing>

    Please use the following line for your real XML:

    <xsl:value-of select="concat(ms:format-date(concat(substring(.,1,4),'-', substring(.,5,2), '-', substring(.,7,2)), 'yyyy-MM-dd'),'T00:00:00.00')"/>


    Monday, October 7, 2019 12:59 PM
  • Hi Yitzhak,

    Thank you very much its worked after adding multiple name spaces on the xslt and after adding Concate statement on date field.

    <xsl:value-of select="concat(ms:format-date(concat(substring(.,1,4),'-', substring(.,5,2), '-', substring(.,7,2)), 'yyyy-MM-dd'),'T00:00:00.00')"/>

    Tuesday, October 8, 2019 3:33 PM