Page 1 of 1

Adding topic numbers to webhelp

Posted: Mon Sep 12, 2016 2:25 pm
by Patrik
I have a use-case where the topic numbers need to be visible not only in the PDF but in the webhelp output as well. While adding this was pretty simple for the pdf it appears to require quite some effort for the webhelp!?

What i got so far is:
  • I modified the build_dita_template.xml to allow a custom value for ditaToc.xsl:

    Code: Select all

    
    [...]
    <if>
    <not>
    <isset property="args.tocDita.xsl"/>
    </not>
    <then>
    <property name="args.dita.out.map.webhelp.tocDita.xsl" value="${webhelp.dir}/xsl/dita/tocDita.xsl"/>
    </then>
    </if>
    <xslt processor="trax"
    in="${dita.temp.dir}/${user.input.file}"
    out="${output.dir}/toc.xml"
    style="${args.dita.out.map.webhelp.tocDita.xsl}"
    [...]
  • In my custom ditaToc.xsl I additionally passed the class attribute to the toc:topic elements to allow different numbering (i.e. hide the number for notices and use letters for an appendices).
  • In my custom createMainFiles.xsl I override the function oxygen:getTopicTitle() to add the number in front of the text.
Now before going further this path I'm wondering:
  1. Is this the right way? For the frames html I would have to adapt additional XSLs... An alternative might be to add a preprocess step that modifies the navtitle element within the ditamap!?
  2. How can I comfortably add the topic number to the topic itself. Sicne each topic is processed individually I have no direct access to the corresponding topicref in the ditamap!?
Thanks and regards,
Patrik

Re: Adding topic numbers to webhelp

Posted: Mon Sep 12, 2016 5:49 pm
by radu_pisoi
Hi,
Patrik wrote:Is this the right way? For the frames html I would have to adapt additional XSLs... An alternative might be to add a preprocess step that modifies the navtitle element within the ditamap!?
I didn't try a such customization, so I'm affraid I don't know the right way. The solution that you alredy found seems to be OK.
Patrik wrote:How can I comfortably add the topic number to the topic itself. Sicne each topic is processed individually I have no direct access to the corresponding topicref in the ditamap!?
You can try to find the associated topic in the temporary DITA map by looking for its relative path. The 'dita2webhelp.xsl' stylesheet already receives two parameters: FILEDIR and FILENAME. I think you can use they to compute the path to the topic and then find the associated topic in the DITA map using this path.

The code for computing the topic path might be:

Code: Select all

<!-- Extract the file name without extension -->
<xsl:variable name="FILENAME_WITHOUT_EXT" select="oxygen:getFileName($FILENAME)"/>

<!-- Compute the output file name -->
<xsl:variable name="OUT_FILENAME" select="concat($FILENAME_WITHOUT_EXT, $OUT_FILE_EXT)"/>

<!-- The path for the current file -->
<xsl:variable name="current-file"
select="
translate(
if ($FILEDIR = '.') then
$OUT_FILENAME
else
concat($FILEDIR, '/', $OUT_FILENAME), '\', '/')"/>

Re: Adding topic numbers to webhelp

Posted: Tue Sep 13, 2016 2:57 pm
by Patrik
Hi Radu,

thanks for your thoughts. Since I found several other things I'd have to modify (especially all kind of links within the map) I decided to implement it as an additional step in the preprocess.

So if anyone else should have the same requirement and comes across this thread - just tell me and I will make it open-source...

Patrik