Generate today's date in output

protl
Posts: 13
Joined: Mon Dec 18, 2017 10:52 pm

Generate today's date in output

Post by protl » Wed May 02, 2018 2:49 pm

Does Oxygen or DITA have a field or similar that can be inserted in the DITA code in order to show today's date in the output when a transform runs? I have code similar to the following in a content file, and want to auto-populate the date, based on the date when the transform runs: <p>Update Date: <DATE GOES HERE></p>

alin
Site Admin
Posts: 143
Joined: Thu Dec 24, 2009 11:21 am

Re: Generate today's date in output

Post by alin » Thu May 03, 2018 6:18 pm

Hello,

There is no out of the box setting that would allow you to insert the current date or time in the generated output.
However, for the WebHelp Responsive output, you can achieve this behavior by contributing a custom XSLT extension stylesheet.
You can use the following example as starting point: https://www.oxygenxml.com/doc/versions/ ... hp1_phg_dx
You can find the sample files for the above example on GitHub (see the "Generation Date & Time" template): https://github.com/oxygenxml/oxygen-pub ... te-samples

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com

rdelong
Posts: 71
Joined: Tue Oct 21, 2014 10:01 pm

Re: Generate today's date in output

Post by rdelong » Thu May 03, 2018 6:49 pm

We use this method for obtaining the current year for our copyrights page:

Code: Select all

<xsl:param name="YEAR" select="year-from-dateTime(current-dateTime())"/>
This page might be of help as well to build the publication date that you desire:
https://www.w3schools.com/js/js_date_methods.asp

protl
Posts: 13
Joined: Mon Dec 18, 2017 10:52 pm

Re: Generate today's date in output

Post by protl » Fri May 04, 2018 10:54 pm

Thanks for the suggestions! I am generating PDF output, and new to XSL. Similar to the YEAR example that you provided, I found the format below online for an MM/DD/YY date, but it appears that you cannot simply paste this into the DITA; the transform fails. Can anyone tell me how to add this code in a way that generates the date in the output? Does the DITA code have to call the variable somehow, after the variable is defined?

HERE IS THE CODE THAT CAUSES MY TRANSFORM TO FAIL:
<p>Update Date: <xsl:variable name="bc.currentDate"
select="format-date(current-date(), '[M01]/[D01]/[Y0001]')"/></p>

alin
Site Admin
Posts: 143
Joined: Thu Dec 24, 2009 11:21 am

Re: Generate today's date in output

Post by alin » Mon May 14, 2018 2:58 pm

Hello,

You cannot use XSLT fragments directly in the DITA sources. If you want to customize the PDF output you can have a look at this topic in our User Manual:
https://www.oxygenxml.com/doc/versions/ ... ation.html
You can also read more about this subject in the DITA-OT 2.x documentation:
http://www.dita-ot.org/dev/topics/pdf-c ... ation.html

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply