Modifying ORG.DITA.HTML5 plugin's tables.xsl file

69 views
Skip to first unread message

cant0r

unread,
Aug 23, 2021, 11:15:22 AM8/23/21
to DITA-OT Users

Hi All,

I want to alter the numbering behaviour of the tables/figures for the html5 transtype as the "counter" is reset to 1 for every topic we process.

I created a small plugin for myself that has a modified tables.xsl file and the only thing it does that it copies this stylesheet to the org.dita.html5/xsl folder overwriting the tables.xsl file there just after the preprocessing finished.

(I know it's really weird but I'm not allowed to create a new transtype.)

But when the html5.topic target runs I get the following:
Caused by: net.sf.saxon.s9api.SaxonApiUncheckedException: file:/D:/InfoShare/Data/Publish/Data/2ajh51n4p2a/work/temp/software-requirements.dita at org.dita.dost.util.XMLUtils$1.message(XMLUtils.java:171)

Naturally, this is because of the change I made.
My question is why DITA-OT(or Saxon?) fails to process the following tables.xsl stylesheet, I'll only link the important parts for you:

```
<xsl:template match="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]" mode="label">
    <span class="table--title-label">
      <xsl:apply-templates select="." mode="title-number">
        <xsl:with-param name="number" as="xs:integer">
          <xsl:call-template name="get-actual-table-figure-id">
            <xsl:with-param name="search-id" select="parent::*[contains(@class, ' topic/table ')][1]/@id"/>
          </xsl:call-template>
        </xsl:with-param>
      </xsl:apply-templates>
    </span>
  </xsl:template>
```

If I remove that template call then it compiles successfully.
The " get-actual-table-figure-id" template looks like this:
```
  <xsl:template name="get-actual-table-figure-id">
    <xsl:param name="search-id"/>
    <xsl:message terminate="no">YES YES YES</xsl:message>
    <xsl:message terminate="no">
      <xsl:value-of select="document-uri(/)"/>
    </xsl:message>
    <xsl:variable name="merged" select="document-uri(/)"/>
    <xsl:number value="count(preceding::*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]) +1"/>   
    
  </xsl:template>
```

This template is located in that same tables.xsl file.

Oxygen Editor shows no syntax problem with this.

Thank you in advance



Radu Coravu

unread,
Aug 24, 2021, 1:23:16 AM8/24/21
to cant0r, DITA-OT Users
Hi,

Can you maybe post more details from the DITA OT console? The 5-10 lines before and after the "Caused by" message?

Regards,
Radu

--
You received this message because you are subscribed to the Google Groups "DITA-OT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dita-ot-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/dita-ot-users/b980482e-fd7d-4383-8a84-3399b5e82c9fn%40googlegroups.com.

cant0r

unread,
Aug 25, 2021, 2:20:54 AM8/25/21
to DITA-OT Users
Hi Radu,

Here's more context to this, I'm also attaching what the build.xml and plugin.xml of my plugin just in case..

```
Caused by: java.lang.RuntimeException: Internal error evaluating template rule at line 581 in module file:/D:/InfoShare/App/Utilities/DITA-OT/DITA-OT3.6/plugins/org.dita.html5/xsl/tables.xsl at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:371)

at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:533) at net.sf.saxon.expr.instruct.ApplyTemplates.apply(ApplyTemplates.java:300)
at net.sf.saxon.expr.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:255) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:353)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:300) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:352)
... 113 more

Caused by: java.lang.RuntimeException: Internal error evaluating template rule at line 590 in module file:/D:/InfoShare/App/Utilities/DITA-OT/DITA-OT3.6/plugins/org.dita.html5/xsl/tables.xsl at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:371)

at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:533) at net.sf.saxon.expr.instruct.ApplyTemplates.apply(ApplyTemplates.java:300)
at net.sf.saxon.expr.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:255) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:353)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:300)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:352)
... 122 more
```

And the plugin.xml:
```
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="dita-ot/plugin.rnc" type="application/relax-ng-compact-syntax"?>
<plugin id="html-helper">
    <require plugin="org.dita.pdf2"/>    
    <feature extension="ant.import" file="build.xml"/>
    <feature extension="depend.preprocess.post" value="rt-fix"></feature>
</plugin>

```
Finally, the build.xml:

```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:dita="http://dita-ot.sourceforge.net" xmlns:if="ant:if" xmlns:unless="ant:unless" name="html-helper">
 
  <target name="rt-fix" depends="rt.init, map2pdf2, rt.override.tables, rt.endit"/>
 
  <target name="rt.init">
    <echo level="info"> "Will this work? Let's find out!"</echo>
  </target>
 
  <target name="rt.endit" depends="">
    <!--<fail message=Success! Look for the work folder!"></fail>-->
  </target>
 
  <target name="rt.override.tables">
    <echo level="info">Copying my table xsl to the org.dita.html5/xsl folder.</echo>
    <copy file="${dita.plugin.html-helper.dir}/xsl/tables.xsl" todir="${dita.plugin.html-helper.dir}/../org.dita.html5/xsl/" overwrite="true"/>
  </target>
 
  <target name="map2pdf2" unless="noMap">
    <dirname property="dita.temp.dir.fullpath" file="${dita.temp.dir}${file.separator}dummy.file"/>
    <pipeline message="topicmerge" taskname="topic-merge" inputmap="${dita.temp.dir.fullpath}${file.separator}${user.input.file}">
      <module class="org.dita.dost.module.TopicMergeModule">
        <param name="output" location="${dita.temp.dir.fullpath}${file.separator}_MERGED.xml"/>
        <param name="style" location="${dita.plugin.org.dita.pdf2.dir}/xsl/common/topicmerge.xsl"/>
      </module>
    </pipeline>
  </target>
 
</project>

```

Radu Coravu

unread,
Aug 25, 2021, 3:57:18 AM8/25/21
to cant0r, DITA-OT Users
Hi,

So looking at your build file you actually copy an entire XSLT stylesheet over the one defined in the base plugin?

    <copy file="${dita.plugin.html-helper.dir}/xsl/tables.xsl" todir="${dita.plugin.html-helper.dir}/../org.dita.html5/xsl/" overwrite="true"/>

This is not how DITA OT XSLT customizations are made.
For example this plugin.xml from a small project I made on GitHub:

uses an extension point to provide an extra XSLT stylesheet for HTML5:

<feature extension="dita.xsl.html5" value="xhtmlEmbed.xsl" type="file"/>

In the XSLT stylesheet provided via the extension point you can copy from the base XSLT stylesheet only the XSLT template that you want to modify. Your XSLT stylesheet will have more priority and it's templates will be used instead of the ones in the base HTML5 plugin.

Regards,
Radu

cant0r

unread,
Aug 25, 2021, 5:49:21 AM8/25/21
to DITA-OT Users
Hi,

I followed your suggestion and modified my plugin to follow the official guidelines but I'm still having this same issue:

```
Caused by: java.lang.RuntimeException: Internal error evaluating template rule at line 568 in module file:/D:/InfoShare/App/Utilities/DITA-OT/DITA-OT3.6/plugins/org.dita.html5/xsl/tables.xsl at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:371) at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:533) at net.sf.saxon.expr.instruct.ApplyTemplates.apply(ApplyTemplates.java:300) at net.sf.saxon.expr.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:255) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735) at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:353) at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:300) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735) at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:352)
... 113 more

Caused by: java.lang.RuntimeException: Internal error evaluating template rule at line 32 in module file:/D:/InfoShare/App/Utilities/DITA-OT/DITA-OT3.6/plugins/html-helper/xsl/tables.xsl
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:371) at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:533)
at net.sf.saxon.expr.instruct.ApplyTemplates.apply(ApplyTemplates.java:300)
at net.sf.saxon.expr.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:255) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:735) at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:132)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:353)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:300)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:352)
... 122 more
```

My tables.xsl got simplified to just:
```
<?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:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
                xmlns:dita2html="http://dita-ot.sourceforge.net/ns/200801/dita2html"
                xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
                xmlns:table="http://dita-ot.sourceforge.net/ns/201007/dita-ot/table"
                version="2.0"
                exclude-result-prefixes="xs dita-ot dita2html ditamsg table">

 
  <xsl:template name="get-actual-table-figure-id">
    <xsl:param name="search-id"/>
    <xsl:message terminate="no">YES YES YES</xsl:message>
    <xsl:message terminate="yes">

      <xsl:value-of select="document-uri(/)"/>
    </xsl:message>
    <xsl:variable name="merged" select="document-uri(/)"/>
    <xsl:number value="count(preceding::*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]) +1"/>   
    
  </xsl:template>
 
 <!-- line 32 -- error occurs here -->

  <xsl:template match="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]" mode="label">
    <xsl:variable name="index">

      <xsl:call-template name="get-actual-table-figure-id">
        <xsl:with-param name="search-id" select="parent::*[contains(@class, ' topic/table ')][1]/@id"/>
      </xsl:call-template>
    </xsl:variable>

    <span class="table--title-label">
      <xsl:apply-templates select="." mode="title-number">
        <xsl:with-param name="number" as="xs:integer">
          <xsl:value-of select="$index"/>

        </xsl:with-param>
      </xsl:apply-templates>
    </span>
  </xsl:template>

</xsl:stylesheet>

```
And the plugin.xml:
```
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="dita-ot/plugin.rnc" type="application/relax-ng-compact-syntax"?>
<plugin id="html-helper">
    <require plugin="org.dita.pdf2"/>    
    <require plugin="org.dita.html5"/>

    <feature extension="ant.import" file="build.xml"/>    
    <feature extension="dita.xsl.html5" value="xsl/tables.xsl" type="file"/>

    <feature extension="depend.preprocess.post" value="rt-fix"></feature>
</plugin>
```

I have also removed the copy task from build.xml file.

Radu Coravu

unread,
Aug 25, 2021, 7:25:28 AM8/25/21
to cant0r, DITA-OT Users
Hi,

Not sure, I see you have a message with terminate='yes' in your XSLT, maybe you can remove that as well.
Other than that if the problem still occurs, if you can put together a small DITA OT plugin with which the problem can be reproduced, zip it and attach it to an mail maybe I can take a look.

Regards,
Radu

cant0r

unread,
Aug 25, 2021, 10:20:00 AM8/25/21
to DITA-OT Users
Hi Radu,

I've managed to resolve my issue. The template failed to compile because of this message call:
<xsl:message terminate="yes">

      <xsl:value-of select="document-uri(/)"/>
    </xsl:message>

Inside the template "root" couldn't be used as we passed no node(s) during template call to the template so it produced this undefined behavior or the XSLT processor saw a set of nodes actually so the concept of root was basically inapplicable here.

Well, at least I think this is the case here, please correct me if I'm wrong.

Now I pass "/" to the template during template call and everything works as expected instead of directly using root in document-uri.

Thank you for your help with this!

Regards,
Tamás

Radu Coravu

unread,
Aug 26, 2021, 12:11:25 AM8/26/21
to cant0r, DITA-OT Users
Hi Tamás,

I'm glad you sorted this out.

Regards,
Radu

Reply all
Reply to author
Forward
0 new messages