Webhelp hazard statement XSLT extension point

Post here questions and problems related to editing and publishing DITA content.
steinbacherGE
Posts: 55
Joined: Tue Mar 13, 2018 6:07 pm

Webhelp hazard statement XSLT extension point

Post by steinbacherGE »

We use a custom Webhelp extension point that overrides the HTML5 XSL template for hazardstatement.

"C:\DITA-OT3.x\plugins\org.dita.html5\xsl\hazard-d.xsl"

Our extension includes the whole HTML5 hazardstatement table from hazard-d.xsl. We've copied the template from this file and modified the use of symbols and borders. We also added conditional statements to differentiate 2 different hazard statement styles that are controlled by a parameter.

The latest Webhelp release v23.1 now includes its own extension of this template.

"C:\DITA-OT3.x\plugins\com.oxygenxml.webhelp.responsive\xsl\dita2webhelp\html5-pdf-webhelp\html5-hazard.xsl"

But the new Webhelp extension breaks into different parts:
  • Call original template from org.dita.html5/xsl/hazard-d.xsl.
  • Add hazard type to class attribute.
  • Add hazard header in a thead element and define colgroup.
  • Add hazard content into a tbody element.
What is the best way to adapt our original hazardstatement custom extension to take into consideration the structure of the new webhelp extension templates listed above?

Is there a way to call our extension of the HTML5 hazard-d.xsl instead of the original one?

Or should we extend the new html5-hazard.xsl templates instead?
julien_lacour
Posts: 498
Joined: Wed Oct 16, 2019 3:47 pm

Re: Webhelp hazard statement XSLT extension point

Post by julien_lacour »

Hello,

An easy way to integrate your plugin together with our is to use the following workflow:
  1. Use a template to match the same element as the default from hazard-d.xsl/html5-hazard.xsl and use a variable and the next-match call to save the returned fragment.

    Code: Select all

      <xsl:template match="*[contains(@class,' hazard-d/hazardstatement ')]">
        <xsl:variable name="nm">
          <xsl:next-match/>
        </xsl:variable>
        <xsl:apply-templates select="$nm" mode="custom"/>
      </xsl:template>
    
    This fragment contains modifications for both hazard-d.xsl and html5-hazard.xsl (html5-hazard.xsl calls hazard-d.xsl on the same manner using next-match and a variable).
  2. Create a copy-template ("ct" in Oxygen autocompletion) that copies the fragment using your custom mode.

    Code: Select all

      <xsl:template match="node() | @*" mode="custom">
        <xsl:copy>
          <xsl:apply-templates select="node() | @*" mode="#current"/>
        </xsl:copy>
      </xsl:template>
    
  3. Add you custom templates, don't forget the mode.

    Code: Select all

      <!-- Add your custom templates. -->
      <xsl:template match="table" mode="custom">
        ...
      </xsl:template>
      <xsl:template match="td" mode="custom">
        ...
      </xsl:template>
      ...
    
    Like this you will have modifications from both style-sheets.
Regards,
Julien
steinbacherGE
Posts: 55
Joined: Tue Mar 13, 2018 6:07 pm

Re: Webhelp hazard statement XSLT extension point

Post by steinbacherGE »

Thank you for the explanation and the workflow.

Our custom table template wraps the content that is inside the <th> element with a <span> element.

Code: Select all

<th colspan="2" class="hazardstatement--danger">
<span>
<svg >..</svg> DANGER
</span>
</th>
This allows us to apply a custom style to just the span element that contains the hazardstatement symbol and type.
image.png
image.png (8.47 KiB) Viewed 1259 times
I tried the following template, but it adds an empty span element at the end of the table instead of inside the <th> element.

Code: Select all

<!-- Add your custom templates. -->
    <xsl:template match="th" mode="custom">
        <span>
            <xsl:copy-of select="."/>
        </span>
    </xsl:template>
Any suggestions on how to add a <span> element inside the <th> element?

Thanks,

Leroy
julien_lacour
Posts: 498
Joined: Wed Oct 16, 2019 3:47 pm

Re: Webhelp hazard statement XSLT extension point

Post by julien_lacour »

Hello,

Your template cannot work because the <span> will be generated before the <th> element which is not valid in a table.
This is the result of your template:

Code: Select all

<span>
    <th colspan="2" class="hazardstatement--danger">
        <svg xmlns="http://www.w3.org/2000/svg" class="hazardsymbol" version="1.1" height="1em" viewBox="0 0 600 525">
        ...
        </svg>
         DANGER
     </th>
</span>
You need first to generate the <th> (with its attributes), emit the <span> and copy all its children (with <xsl:apply-templates/>):

Code: Select all

<xsl:template match="th" mode="custom">
  <th>
    <xsl:copy-of select="@*"/>
    <span>
      <xsl:apply-templates/>
    </span>
  </th>
</xsl:template>
Regards,
Julien
steinbacherGE
Posts: 55
Joined: Tue Mar 13, 2018 6:07 pm

Re: Webhelp hazard statement XSLT extension point

Post by steinbacherGE »

Thanks Julien!

Your suggestion works as expected. :D
Post Reply