Page 1 of 1

Need to put Last Updated in the body of a topic

Posted: Thu Sep 03, 2020 5:27 am
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?

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

Posted: Fri Sep 04, 2020 6:18 pm
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

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

Posted: Wed Sep 16, 2020 12:16 am
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?

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

Posted: Fri Sep 18, 2020 9:10 am
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

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

Posted: Mon Sep 28, 2020 8:15 pm
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

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

Posted: Tue Sep 29, 2020 12:27 pm
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

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

Posted: Tue Sep 29, 2020 11:34 pm
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

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

Posted: Wed Sep 30, 2020 3:16 am
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 85 times

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

Posted: Thu Oct 01, 2020 5:27 pm
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

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

Posted: Thu Oct 01, 2020 9:55 pm
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 83 times

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

Posted: Fri Oct 02, 2020 3:35 pm
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

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

Posted: Fri Oct 02, 2020 8:22 pm
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

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

Posted: Mon Oct 05, 2020 12:59 pm
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

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

Posted: Mon Oct 12, 2020 10:30 pm
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

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

Posted: Mon Mar 29, 2021 10:27 pm
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 55 times

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

Posted: Tue Mar 30, 2021 9:54 am
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

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

Posted: Wed Mar 31, 2021 8:54 pm
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.

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

Posted: Thu Apr 01, 2021 9:32 am
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

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

Posted: Fri Apr 02, 2021 6:03 am
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!

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

Posted: Tue Apr 06, 2021 12:46 pm
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

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

Posted: Wed Apr 07, 2021 7:59 am
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!

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

Posted: Thu Apr 08, 2021 2:25 pm
by cosmin_andrei
Hello,

This issue has been resolved in a maintenance build which will be available in the next week.

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

Posted: Tue Apr 13, 2021 12:58 pm
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

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

Posted: Wed Apr 14, 2021 12:13 am
by toolie
Thank you so much! We will update the software and run a test to confirm the fix on our end.