format-date

Questions about XML that are not covered by the other forums should go here.
tAnd
Posts: 3

format-date

Tue Jan 15, 2019 5:23 pm

Hello

I have created a 1.0 stylesheet but i need the IssueDate to be in the form of YYYY-MM-DD. Now it is YYYYMMDD.
I have tried using

Code: Select all

<xsl:template match="IssueDate">
      <td>
         <xsl:value-of select="format-date(.,'[Y0001]-[M01]-[D01]')"/>
      </td>
   </xsl:template>
   

but it doesent work.

Anyone who knows what to do?
Thank you in advance.
Radu
Posts: 5992

Re: format-date

Wed Jan 16, 2019 4:03 pm

Hi,

I'm not sure what you mean by "it does not work" but "format-date()" is an XSLT 2.0 function:

https://www.w3.org/TR/xslt20/#function-format-date

so you cannot use it in an XSLT 1.0 stylesheet.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
tAnd
Posts: 3

Re: format-date

Wed Jan 16, 2019 4:22 pm

Yes i figured that out. But the question is then - how should i do it in xslt 1.0?
Radu
Posts: 5992

Re: format-date

Wed Jan 16, 2019 4:25 pm

Hi,

You need to do it the hard way using substring-before, substring-after and so on.
I found a stackoverflow post about this:

https://stackoverflow.com/questions/16484193/convert-date-from-dd-mmm-yyyy-to-yyyymmdd-format-in-xslt-1-0

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “General XML Questions”

Who is online

Users browsing this forum: Google [Bot] and 0 guests