Need to put Last Updated in the body of a topic

toolie
Posts: 14
Joined: Thu Jan 29, 2015 2:40 am

Need to put Last Updated in the body of a topic

Post by toolie » Thu Sep 03, 2020 5:27 am

Hi there, I think I've read everything in your documentation about how to insert HTML fragments into code, and I'm still missing the one thing I need: to put the Last Modified date of the individual files into the body of each topic so that the reader knows how fresh the content is. I already have the Generation Date going in the footer, but I need each topic to display its Last Modified date.

I can retrieve the date using Javascript; I can even put that into an HTML fragment. But there doesn't seem to be a way to put the code into the body of the topic. All your documentation discusses is putting into one of the prescribed locations in the structural portions of the Webhelp Responsive template (header, footer, etc).

What do I do to have the following:

Last modified: 2-Sep-2020 <-- file modification date

appear at the bottom of the topic?
Toolie Garner

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

Re: Need to put Last Updated in the body of a topic

Post by alin » Fri Sep 04, 2020 6:18 pm

Hello,

You can use a custom XSLT file to insert your content at the end of the topic. For example:
content-after-topic.xsl

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:whc="http://www.oxygenxml.com/webhelp/components"
    exclude-result-prefixes="xs"
    version="3.0">
    
    <xsl:template match="whc:webhelp_topic_content" mode="copy_template">
        <xsl:next-match/>
        <div><b>Custom content after topic</b></div>
    </xsl:template>
</xsl:stylesheet>
You can contribute your XSLT file to the WebHelp Responsive output using the XSLT Extension support. Include your XSLT file in your Publishing Template and register it on the "com.oxygenxml.webhelp.xsl.dita2webhelp" XSLT Extension Point. Add the following fragment to your Publishing Template descriptor file (.opt):

Code: Select all

<xslt>
    <extension file="content-after-topic.xsl" id="com.oxygenxml.webhelp.xsl.dita2webhelp"/>
</xslt>

Considering that the Last Modified info is included in each DITA topic as metadata you should replace <div><b>Custom content after topic</b></div> with the appropriate XSLT instructions that extract that information from the DITA source.
You can also use the file:last-modified() XSLT function to extract that information directly from the DITA source file itself: https://www.saxonica.com/html/documenta ... ified.html


You can read more about the XSLT Extension feature in our User Guide: https://www.oxygenxml.com/doc/versions/ ... mport.html

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

toolie
Posts: 14
Joined: Thu Jan 29, 2015 2:40 am

Re: Need to put Last Updated in the body of a topic

Post by toolie » Wed Sep 16, 2020 12:16 am

Thank you so much for the additional information; it seems I was on the right track but I'm still missing information. According to the Saxon documentation, what should appear is:

file:last-modified($path as xs:string) as xs:dateTime

Here's my code: clearly I'm missing something because it's not working:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:whc="http://www.oxygenxml.com/webhelp/components"
    exclude-result-prefixes="xs"
    version="3.0">
    
    <xsl:template match="whc:webhelp_topic_content" mode="copy_template">
        <xsl:next-match/>
        <div style="font-size:0.75em;font-weight:bold;">file:last-modified($path as xs:string) as xs:dateTime</div>
    </xsl:template>
</xsl:stylesheet>
Writing XSL is not my strong suit; can you help?
Toolie Garner

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

Re: Need to put Last Updated in the body of a topic

Post by alin » Fri Sep 18, 2020 9:10 am

Hello,

This is how your XSLT extension should look like:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:whc="http://www.oxygenxml.com/webhelp/components"
    xmlns:file="http://expath.org/ns/file"
    exclude-result-prefixes="xs file whc"
    version="3.0">
    
    <xsl:template match="whc:webhelp_topic_content" mode="copy_template">
        <xsl:param name="i18n_context" select="/*" tunnel="yes" as="element()"/>
        <xsl:next-match/>
        <xsl:variable name="docUri" select="$i18n_context/*/@xtrf"/>
        <div style="font-size:0.75em;font-weight:bold;">
             <xsl:value-of select="file:last-modified($docUri[1])"/>
        </div>
    </xsl:template>
</xsl:stylesheet>
Unfortunately, according the Saxonica documentation, the file:last-modified() function is only available in the Saxon-PE and Saxon-EE distributions. DITA-OT comes bundled with Saxon HE which means that you cannot use the above XSLT extension point out-of-the-box in WebHelp Responsive.

If you are generating WebHelp Responsive output using a transformation scenario from Oxygen XML Editor or Author you can configure the transformation to use the Saxon EE library that is bundled in Oxygen:
  1. In the DITA Map Manager View click the Configure Transformation Scenario(s) icon on the view's toolbar.
  2. Edit your copy of DITA Map WebHelp Responsive transformation scenario.
  3. Got to Advanced tab
  4. Click on Libraries button
  5. Uncheck Allow Oxygen to add high priority libraries to the classpath
  6. Scroll down the list
  7. Select the ${oxygenHome}/lib/*saxon*9*.jar entry
  8. Click on Up arrow button on the right until the selected entry reaches the top of the list
  9. Save the transformation scenario
Image

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

toolie
Posts: 14
Joined: Thu Jan 29, 2015 2:40 am

Re: Need to put Last Updated in the body of a topic

Post by toolie » Mon Sep 28, 2020 8:15 pm

Alin, thank you so much for the extra work you put in on this response -- I very much appreciate it. I followed both the written steps, and the visual step-by-step (that was awesome!), but I am not seeing the Last Modified date/time appear at the end of each topic as desired. Is there something I should be putting into each topic as a place for that information to match?

Toolie
Toolie Garner

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

Re: Need to put Last Updated in the body of a topic

Post by alin » Tue Sep 29, 2020 12:27 pm

Hello Toolie,

There is no need for additional information to be included in the topics. The date and time should have been displayed at the bottom of each topic.
I have retested the solution mentioned above and the timestamp is there.
I have included all the resources in a sample Publishing Template that I have uploaded on our GitHub repository: https://github.com/oxygenxml/oxygen-pub ... in-content
This is how the date and time is displayed on my side when using the above template:
Image
Please try to use this template and see if it works for you. By the way I am using Oxygen 22.1. What version of Oxygen are you using?

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

toolie
Posts: 14
Joined: Thu Jan 29, 2015 2:40 am

Re: Need to put Last Updated in the body of a topic

Post by toolie » Tue Sep 29, 2020 11:34 pm

Again, thank you so much for the time you've invested in providing the code. I"m going to do a file comparison of yours with mine, and see whether there's something I'm doing that is impeding the display of the Last Modified date. I'll get back to you whether I have questions or whether I succeed in figuring out what wasn't working in my code.

I am hoping that eventually, between the two of us, we can add this code and explanation to the overall documentation. I know for a fact that I'm not the only one interested in being able to individually mark the pages with a recency date.

Thanks again,
Toolie
Toolie Garner

toolie
Posts: 14
Joined: Thu Jan 29, 2015 2:40 am

Re: Need to put Last Updated in the body of a topic

Post by toolie » Wed Sep 30, 2020 3:16 am

Hi Alin, I aligned my OPT and CSS files with the ones you provided, and successfully ran the build, and the Last Modified date did not show up. I then created a separate publishing template and ran my projects against it and got errors. I've zipped up the error log and images containing the error explanations. Hopefully these will help.

If you want me to upload my publishing template files, let me know.

Thanks!
Toolie
20200929-toolie-garner-build-errors.zip
(103.31 KiB) Downloaded 10 times
Toolie Garner

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

Re: Need to put Last Updated in the body of a topic

Post by alin » Thu Oct 01, 2020 5:27 pm

Hi Toolie,

According to your error-log.txt the transformation scenario does not promote the Saxon library bundled with Oxygen (oxygenxml\lib\oxygen-patched-saxon-9.jar) before the Saxon library bundled in the DITA-OT distribution (DITA-OT3.x\lib\Saxon-HE-9.9.1-4.jar). Please see the screenshot below:
Image

The error you have encountered is related to the fact that the file:last-modified() is not supported by the Saxon HE distribution your transformation is run with.
Here is the actual error extracted from error-log.txt:

Code: Select all

whr-dita-inner-topics:
 [pipeline] Transforming into D:\mydocs\XMLProj\provdocs\out\webhelp-responsive
 [pipeline] Static error in {file:last-modified($docUri[1])} in expression in xsl:variable/@select on line 14 column 88 of last-modified-in-content.xsl:
 [pipeline]   XPST0017: Cannot find a 1-argument function named Q{http://expath.org/ns/file}last-modified()

I did noticed your screenshot with the order for the libraries but it is possible that:
  1. you have not saved the transformation scenario after applying the modification
  2. or you are running the transformation with a different scenario than the one you have modified
Please check the associated scenario and if it is the right one please make sure that it has the libraries order changed.

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

toolie
Posts: 14
Joined: Thu Jan 29, 2015 2:40 am

Re: Need to put Last Updated in the body of a topic

Post by toolie » Thu Oct 01, 2020 9:55 pm

Hi Alin, thank you for your help. I did indeed save the transformation after applying the change -- I could tell because the number on the "Libraries" button said 44, just like it did when I applied your scenario. I had forgotten to save it on YOUR template, and when I did, then the LastModified did appear.

I've attached my publishing template because I suspect there's a setting in it that's causing a conflict and preventing my template from display the LastModified in my documents. I did a line-by-line comparison of the settings in the .OPT file but didn't see anything that might interfere. I am using the Last Generation XSLT fragment in the footer and wondered whether that might be the problem, but commenting that out had no effect. I still do not see the LastModified in my pages.

If you need me to share the various settings within the transformation scenarios, I can do that as well, but I thought we'd start with my CSS and OPT files. Can you help? They're attached in a zip file.

Thank you!
Toolie
prov-html-template.zip
(13.94 KiB) Downloaded 9 times
Toolie Garner

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

Re: Need to put Last Updated in the body of a topic

Post by alin » Fri Oct 02, 2020 3:35 pm

Hi Toolie,

The problem is in your Publishing Template's descriptor file. You have two XSL files registered for the same XSLT Extension Point (com.oxygenxml.webhelp.xsl.dita2webhelp):

Code: Select all

<extension file="xslt/generation-time.xsl" 
	id="com.oxygenxml.webhelp.xsl.dita2webhelp"/>
<extension file="xslt/last-modified-in-content.xsl"
	id="com.oxygenxml.webhelp.xsl.dita2webhelp"/>
You should have only one XSLT file per extension point.
The solution is to import both XSLT files from a third one and have the last one registered on the com.oxygenxml.webhelp.xsl.dita2webhelp extension point.
topic-customization.xsl:

Code: Select all

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="3.0">
    
    <xsl:import href="last-modified-in-content.xsl"/>
    <xsl:import href="generation-time.xsl"/>
    
</xsl:stylesheet>
Template's descriptor file:

Code: Select all

<extension file="xslt/topic-customization.xsl"
                id="com.oxygenxml.webhelp.xsl.dita2webhelp"/>
The rest of the XSLT Extension Points declarations should remain unchanged.
You can download the modified Publishing Template from here: http://www.oxygenxml.com/forum/files/pr ... dified.zip

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

toolie
Posts: 14
Joined: Thu Jan 29, 2015 2:40 am

Re: Need to put Last Updated in the body of a topic

Post by toolie » Fri Oct 02, 2020 8:22 pm

Thank you again Alin, this is awesome. I would not have picked up on the fact that I could register only one XSL file for the same XSLT Extension point. I changed the files as described, and now the LastModified date appears! Fantastic!

One final request because I know my boss will ask: is there a way to format that output to match our time zone GMT -8:00 (-7:00 due to Daylight Saving Time) and look like:

02-Oct-2020 09:56 am (GMT -7)

Let me know, and thank you very much!
Toolie
Toolie Garner

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

Re: Need to put Last Updated in the body of a topic

Post by alin » Mon Oct 05, 2020 12:59 pm

Hello,

You should use the following XSLT functions: Please update your XSLT file with the following snippet:

Code: Select all

<time datetime="{$lastModified}">
    <xsl:value-of select="format-dateTime(adjust-dateTime-to-timezone($lastModified, xs:dayTimeDuration('-PT7H0M')), '[D01]-[MNn]-[Y] [h01]:[m] [P] [z1]')"/>
</time>
Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com

toolie
Posts: 14
Joined: Thu Jan 29, 2015 2:40 am

Re: Need to put Last Updated in the body of a topic

Post by toolie » Mon Oct 12, 2020 10:30 pm

Alin, thank you so much for your help with this request -- I'm thrilled with the results, and I know my boss will be very happy.

I don't know whether you have influence over the documentation team, but please, please ask them to write this up and include it in the official documentation. If I have time, I will do it myself and submit it for inclusion (I have 25+ years experience as a tech writer).

Best wishes,
Toolie Garner
Toolie Garner

Post Reply