This is my input xml file

<Root>
<child>
  <element_DateCreated> 2022-05-25T21:34:36Z </element_DateCreated>
</child
</Root>

Input datetime format : 2022-05-25T21:34:36Z

Expected datetime format : 20220525213436

How to convert datetime in below xslt?

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl=""
                xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <data xmlns:xsi="" xsi:noNamespaceSchemaLocation="../lib/extractpad.xsd" >
      <dataheaders>
        <xsl:for-each>
          <dataheader>
            <dstamp>
              <xsl:value-of select="//Root/child/element_DateCreated"/>
            </dstamp>
          </dataheader>
        </xsl:for-each>
      </dataheaders>
    </data>
  </xsl:template>
</xsl:stylesheet>
2

In XSLT 2.0 or higher you can use:

<xsl:value-of select="format-dateTime(/Root/child/element_DateCreated, '[Y0001][M01][D01][H01][m01][s01]')"/>

In any version you can do:

<xsl:value-of select="translate(/Root/child/element_DateCreated, '-:TZ ', '')"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.