Display current date in XML element
43,740
What exactly is happening (what does "no success" mean). What XSLT processor are you using?
Here is a minimal test case of what you are trying to do (input XML document doesn't matter)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="dateNow" select="current-dateTime()"/>
<xsl:variable name="dateNow2" select="current-date()"/>
<xsl:template match="/">
<FL><xsl:value-of select="format-dateTime($dateNow, '[Y0001][M01][D01]')"/></FL>
</xsl:template>
</xsl:stylesheet>
and here is what it produces -- do you get the same if you try this test case?
<?xml version="1.0" encoding="UTF-8"?>
<FL>20120111</FL>
Author by
Gerardo
Updated on July 09, 2022Comments
-
Gerardo almost 2 years
I'm using an XSL to transform one XML into another. My problem is that in one element I have to display the current date with the format:YYYYMMDD.
I tried using a variable like these:
<xsl:variable name="dateNow" select="current-dateTime()"/> <xsl:variable name="dateNow2" select="current-date()"/>
And then tried to format then, but no success.
<FRUEHESTER_LIEFERTERMIN><xsl:value-of select="format-dateTime($dateNow, '[Y0001][M01][D01]')"/></FRUEHESTER_LIEFERTERMIN>
-
Gerardo over 12 yearsHi Murray. I tried with your example but I got 2012111, I'm starting to think that this could be due to the program I use to test xsls that is Altova XMLSpy2006. The process is developed in Sonic. I will test it running the process and let you know. Thanks for your help!
-
Murray McDonald over 12 yearsGerado -- I tried it using ALTOVAXML2012 and Saxon 9 HE -- both produced the same correct result. Take care
-
Gerardo over 12 yearsI tested in my Sonic process and works perfect! The XMLSpy was removing the 0 from dates, damn tool. Thanks again Murray.