Page 1 of 1

How to use XSLT variables in my customized webhelp

Posted: Tue Apr 12, 2022 9:00 am
by maglid
I need to use some DITA OT XSLT variables in my webhelp output. Things like the title of the ditamap, some Tridion Docs metadata like Date Last Modified, etc. I want to add these values to the webhelp topics. How can I access them? I have not yet found a webhelp parameter for this.

Thanks,
Mark

Re: How to use XSLT variables in my customized webhelp

Posted: Wed Apr 13, 2022 7:05 am
by maglid
I'm assuming it's the usual: Find the existing XSLT variables or add ones of my own, and then find the proper XSLT to use them in.
I was just trying to find out if, somewhere in webhelp's many many variables, there was some way to pass a variable into a webehlp config file, for example.

Mark

Re: How to use XSLT variables in my customized webhelp

Posted: Wed Apr 13, 2022 12:58 pm
by alin
Hello,

The Oxygen WebHelp Responsive output can be customized using XSLT Extension files. There are several XSLT-Import Extension points available. For each extension point you can access the global variables that are available in the XSLT context where the extension file is loaded.
The available XSLT-Import Extension points and their associated XSLT files are listed in our User Manual: XSLT-Import Extension Points.

You can also customize the WebHelp output by inserting additional content using custom HTML Fragment files. Using this technique you can insert dynamic content in your output HTML pages with the help of WebHelp Macros, which are variables that will be expanded when the content of the HTML fragment file will be copied in the final output.

We have a repository of custom Publishing Templates that cover different customization topics: https://github.com/oxygenxml/oxygen-pub ... /templates
Maybe the following templates would help you: Regards,
Alin

Re: How to use XSLT variables in my customized webhelp

Posted: Mon May 23, 2022 9:50 am
by maglid
Thanks for the info Alin, it helps. I can do some of the things I want to do, but I am finding that the normal DITA OT variables that are usually available in the XSLT are not available in some of the webhelp XSLT. For example, I am overriding this webhelp template from com.oxygenxml.webhelp.responsive/xsl/dita2webhelp/dita2webhelpImpl.xsl:

Code: Select all

<!-- Normal Webhelp transformation, filtered. -->
    <xsl:template match="/">
        <xsl:variable name="template_base_uri" select="base-uri()"/>
        [...]
My code needs to know the input directory where the input ditamap is, but when I add this variable to my plugin, it is not available in the webhelp XSLT. I added this to my plugin.xml:

Code: Select all

<feature extension="dita.conductor.html5.param" value="insertParameters.xml" type="file"/>
My integrator file:

Code: Select all

<dirname property="args.input.dir" file="${args.input}"/>
My insertParameters.xml file:

Code: Select all

<dummy>
    <param name="input.dir.url" expression="${args.input.dir}"/>
</dummy>
Normally this setup would make the variable $input.dir.url available in XLST, but it does not work.
How can I do this? I can eventually figure out what webhelp is doing, but is there an easier way?

Re: How to use XSLT variables in my customized webhelp

Posted: Wed May 25, 2022 8:37 am
by maglid
Update, I found the webhelp XSLT variable I need, it is $DITAMAP_URL. This gives me the location of the source ditamap in my custom override XSLT.

Re: How to use XSLT variables in my customized webhelp

Posted: Fri May 27, 2022 8:30 am
by maglid
Update -- I can now get to the XML metadata file I need to open, using XSLT. But I've tried doc(filename) and document(filename) and it will not let me read into the metadata file, which definitely is there. doc-avalaible() returns false. I'm doing this inside a webhelp template I am overriding. It's this XSLT file:

Code: Select all

dita-ot/plugins/com.oxygenxml.webhelp.responsive/xsl/dita2webhelp/dita2webhelpImpl.xsl
But if I access this same metadata file with XSLT outside the Oxygen webhelp plugin, it works fine, I can read data out of it. Is there some kind of process lock when webhelp runs that would cause XSLT file reading to fail?

Do you think I should just post-process these HTML files to add the metadata I need, instead of trying to hack the Oxygen webhelp XSLT?

Thanks

Re: How to use XSLT variables in my customized webhelp

Posted: Mon May 30, 2022 12:00 pm
by radu_pisoi
Hi,
But I've tried doc(filename) and document(filename) and it will not let me read into the metadata file, which definitely is there. doc-avalaible() returns false.
Please note that relative paths for doc() function are resolved relative to the static base URI.

See more details in the following links:
https://www.saxonica.com/html/documenta ... n/doc.html
https://www.w3.org/TR/xpath-functions-31/#func-doc

Re: How to use XSLT variables in my customized webhelp

Posted: Tue May 31, 2022 12:26 am
by maglid
I fixed the problem. It was a namespace mismatch. The XSLT file from the webehlp code that I am overriding, which seems to be merging XHTML files, has this attribute on it:

Code: Select all

xpath-default-namespace="http://www.w3.org/1999/xhtml"
That means that the stylesheet expects everything to be in the XHTML namespace. My external file has no namespace (it's in the "null namespace") but XPath is looking for the XHTML namespace, so it finds nothing. So I put my <xsl:value-of> (or other instruction) in the null namespace, and then XPath can read into the external XML file:

Code: Select all

<xsl:value-of  xpath-default-namespace="" select="$testxml//ishfield[@name='FTITLE']" />
It's this attribute with the value of "" that sets it to the null namespace and fixes the problem:

Code: Select all

xpath-default-namespace=""
Thanks,
Mark