Need to put Last Updated in the body of a topic

Post here questions and problems related to editing and publishing DITA content.
toolie
Posts: 26
Joined: Thu Jan 29, 2015 2:40 am

Need to put Last Updated in the body of a topic

Post by toolie »

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: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

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: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

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: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

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: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

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: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

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: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

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: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

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 421 times
Toolie Garner
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

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: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

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 426 times
Toolie Garner
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

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: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

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: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

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: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

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
toolie
Posts: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

I just moved from version 22 to version 23.1, and now this code is not working and causing the build to completely fail:

Code: Select all

whr-dita-inner-topics:
 [pipeline] Transforming into H:\Repo\prov_martech_docs\provdocs\out\webhelp-responsive
 [pipeline] Loading stylesheet C:\Users\[userid]\AppData\Local\Oxygen XML Editor 23\frameworks\dita\DITA-OT3.x\plugins\com.oxygenxml.webhelp.responsive\xsl\dita2webhelp\dita2webhelp.xsl
 [pipeline] Static error in {file:last-modified($docUri[1])} in expression in xsl:variable/@select on line 12 column 88 of last-modified-in-content.xsl:
 [pipeline]   XPST0017: [b]Cannot find a 1-argument function named Q{http://expath.org/ns/file}last-modified()[/b]
Here is the code in its entirety. This was working on v22.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<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 class="last-modified">
            <xsl:variable name="lastModified" select="file:last-modified($docUri[1])"/>
            <time datetime="{$lastModified}">
                <xsl:value-of
                    [b]select="format-dateTime(adjust-dateTime-to-timezone($lastModified, xs:dayTimeDuration[/b]('-PT8H0M')), '[D01]-[MNn]-[Y] [h01]:[m] [P] [z1]')"
                />
            </time>
        </div>
    </xsl:template>
</xsl:stylesheet>
You can see how much effort was put into this to get it to work. I don't understand why changing Oxygen XML Editor versions should break it. I've attached the full output so you can see the other errors.

I literally have 2 days left on this job, and MUST solve this! Help!
20210329-console-output-with-errors.zip
(33.75 KiB) Downloaded 407 times
Toolie Garner
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

Hello,

It seems that you need to follow this procedure and update your transformation scenario.
Cannot find a 1-argument function named Q{http://expath.org/ns/file}last-modified()

The file:last-modified function is available only in Saxon EE and PE distributions and the DITA-OT bundled in Oxygen uses a Saxon HE distribution.

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
toolie
Posts: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

Hi Alin, I went back and checked with my successor, and the results of that procedure (from last time) were already set in the .xpr project file that I transferred to him. We verified again that the setting was correct then ran the transformation, and it still fails. What else might be causing this issue? Again, this is a blocker for us.
Toolie Garner
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

Hello,

In my opinion this a classpath issue.
You should check the order of Saxon libraries listed in the transformation's console output and check that the Saxon jar file from {OXYGEN-INTSALL_DIR}/lib is listed before the one bundled in your current DITA-OT. Please see this topic post.
You can also submit the console output to us to analyze it.

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
toolie
Posts: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

Hi Alin, we did double-check to make sure that the Saxon library is first; as I said, that was already set after transferring the project to my successor.

Please see this point in this thread where I uploaded the full console output:
post61596.html#p61542

Hopefully that helps. Thanks!
Toolie Garner
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

Hi,

Sorry for the delayed response. I did managed to reproduce the error in Oxygen 23.1.
I have submitted a task (ID: EXM-47764) to analyze what is the cause of this behavior.

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
toolie
Posts: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

Alin, thank you so much for your response. We are grateful for the good service we receive from you. We will anxiously await a conclusion!
Toolie Garner
cosmin_andrei
Posts: 134
Joined: Mon Jun 12, 2017 10:50 am

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

Post by cosmin_andrei »

Hello,

This issue has been resolved in a maintenance build which will be available in the next week.
Regards,
Cosmin
--
Cosmin Andrei
oXygen XML Editor and Author Support
Radu
Posts: 8991
Joined: Fri Jul 09, 2004 5:18 pm

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

Post by Radu »

Hi,

We released a minor bug fix release of Oxygen 23.1 on our web site and it should have a fix for this problem:
https://www.oxygenxml.com/build_history.html#2021040908

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
toolie
Posts: 26
Joined: Thu Jan 29, 2015 2:40 am

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

Post by toolie »

Thank you so much! We will update the software and run a test to confirm the fix on our end.
Toolie Garner
Alex Thornton
Posts: 5
Joined: Thu Jan 13, 2022 6:02 am

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

Post by Alex Thornton »

Hi,
I'm trying to implement this solution in oXygen XML Editor 24.0, build 2021121518 using OPE and am seeing the same pipeline error that Toolie reported above post61596.html#p61542 .

Code: Select all

[pipeline] Static error in {file:last-modified($docUri[1])} in expression in xsl:variable/@select on line 13 column 88 of content-after-topic.xsl:
 [pipeline]   XPST0017: Cannot find a 1-argument function named Q{http://expath.org/ns/file}last-modified()
I did not have this implemented in previous Oxygen versions so don't know if the problem is on my side, but I've checked the Saxon library and followed all the other instructions.
Could you please see if you are able to reproduce this error in Oxygen 24.0?
Thanks!
Kind regards,
Alex
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

Hello,

I have tested the last-modified-in-content Publishing Template using Oxygen 24.0 and it worked as expected.

The error you have reported is caused by the fact the XSLT customization contained in this Publishing Template is using the file:last-modified() function which is not available in the Saxon distribution bundled in Oxygen Publishing Engine (i. e. Saxon HE). It is only available in the Saxon-PE and Saxon-EE distributions.
However, Oxygen XML Editor (or Author) comes bundled with Saxon EE and all you need to do is to configure the WebHelp Responsive transformation to use the Saxon EE library from Oxygen XML Editor instead of the Saxon HE from Oxygen Publishing Engine.

The procedure is available here: https://github.com/oxygenxml/oxygen-pub ... ive-output

Note that I have updated the procedure and starting with Oxygen 24 you need to perform an extra step. You must uncheck the Prefer using the "dita" command checkbox in the Advanced tab to enable the Libraries button.

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
kmckenna7
Posts: 5
Joined: Mon Dec 10, 2018 10:11 pm

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

Post by kmckenna7 »

Is this going to be added into the product as a standard offering? I have 24.1, and was hoping for an easier solution. :-/
cosmin_andrei
Posts: 134
Joined: Mon Jun 12, 2017 10:50 am

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

Post by cosmin_andrei »

Hello
We do not have in plan to implement it in the near future. We've registered a feature request & we'll update this forum post when the feature is available.
Regards,
Cosmin
--
Cosmin Andrei
oXygen XML Editor and Author Support
Alex Thornton
Posts: 5
Joined: Thu Jan 13, 2022 6:02 am

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

Post by Alex Thornton »

Oxygen XML Editor V25 now seems to be shipped with Saxon-HE-10.6 instead of PE or EE, which breaks this customisation. :roll:
I would argue that all Oxygen XML products need to be shipped with at least Saxon-PE!
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

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

Post by alin »

Hello,

The customization referenced by this topic was designed to work with Saxon PE or EE. It uses the file:last-modified() function that is only available in these distributions of Saxon.
The customization is not broken but it must be run with a DITA-OT instance that has been configured to use Saxon PE or EE instead of the bundled HE distribution.
Oxygen XML Editor does comes bundled with Saxon EE.
DITA-OT comes bundled with Saxon HE. This is true also for the DITA-OT bundled in Oxygen.
In version 24 of Oxygen there was an workaround for configuring the Oxygen's bundled DITA-OT to run with Oxygen's Saxon EE.
In Oxygen 25 or 25.1 the major versions of Saxon from Oxygen (11.x) and DITA-OT (10.x) are different and thus the above workaround does not work anymore.

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