Page 1 of 1

Generate today's date in output

Posted: Wed May 02, 2018 2:49 pm
by protl
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>

Re: Generate today's date in output

Posted: Thu May 03, 2018 6:18 pm
by alin
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

Re: Generate today's date in output

Posted: Thu May 03, 2018 6:49 pm
by rdelong
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

Re: Generate today's date in output

Posted: Fri May 04, 2018 10:54 pm
by protl
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>

Re: Generate today's date in output

Posted: Mon May 14, 2018 2:58 pm
by alin
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