Custom XHTML plugin creation index.html not effecting

坚强是说给别人听的谎言 提交于 2019-12-02 20:59:16

问题


I have created the custom xhtml plugin like this

my plugin.xml code is

<?xml version="1.0" encoding="UTF-8"?>
<!--
  This file is part of the DITA Open Toolkit project.
  See the accompanying license.txt file for applicable licenses.
-->
<plugin id="com.custom.xhtml">
  <!-- extensions -->
  <feature extension="dita.xsl.xhtml" file="xslhtml/dita2xhtml.xsl"/>
  <feature extension="dita.conductor.transtype.check" value="xhtml-custom" type="txt"/>
  <feature extension="dita.conductor.target.relative" file="build.xml"/>
  <!-- change value to match your custom transtype -->
</plugin>

build.xml code is

<?xml version="1.0" encoding="UTF-8"?>
<project name="com.custom.xhtml">
  <import file="build_transtype-custom.xml"/>
</project>

the build_transtype-custom.xml is

<project name="xhtml-custom" default="dita2xhtml-custom">
<property name="transtype" value="xhtml-custom"/>
<target name="dita2xhtml-custom">
<echo>custom HTML transform</echo>
<!-- Set properties here -->
<antcall target="dita2xhtml"/>
</target>
</project>

then I have pasted the base plugin xsl folder to customized plugin the I have changed the xsl named dita2xhtml.xsl

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:import href="dita2html-base.xsl"/>

<xsl:output method="xml" encoding="UTF-8" indent="no"/>

<xsl:variable name="source-chars" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ .'"/>
<xsl:variable name="target-chars" select="'abcdefghijklmnopqrstuvwxyz__'"/>



<xsl:template match="task">
<div class="topic">
<xsl:attribute name="id">
<xsl:value-of select="attribute::id"/>
</xsl:attribute>
<xsl:apply-templates/>
</div>
</xsl:template>



<xsl:template match="task/title">
<h1>Chapter <xsl:number count="task"/>. <xsl:apply-templates/><xsl:text>&#x00A0;</xsl:text><script type="text/javascript" language="JavaScript" src="find5.js"><xsl:text>&#x200B;</xsl:text></script></h1>
</xsl:template>

<xsl:template match="section">
<div class="section" id="{translate(title, $source-chars, $target-chars )}">
<xsl:apply-templates/>
</div>
</xsl:template>


<xsl:template match="taskbody">
<div>
<xsl:apply-templates/>
</div>
</xsl:template>

<xsl:template match="title">

<h2 class="sectiontitle">
<xsl:apply-templates/>
</h2>

</xsl:template>


<xsl:template match="p">
<p>
<xsl:apply-templates/>
</p>    
</xsl:template>

<xsl:template match="steps">
<ol>
<xsl:apply-templates/>
</ol>    
</xsl:template>

<xsl:template match="step">
<li>
<xsl:apply-templates/>
</li>    
</xsl:template>

<xsl:template match="cmd">
<span>
<xsl:apply-templates/>
</span>    
</xsl:template>

<xsl:template match="b">
<strong>
<xsl:apply-templates/>
<xsl:text>&#x200B;</xsl:text>
</strong>    
</xsl:template>

<xsl:template match="menucascade">
<span class="menucascade">
<xsl:apply-templates/>
</span>    
</xsl:template>

<xsl:template match="uicontrol">
<span class="uicontrol">
<xsl:apply-templates/>
</span>    
</xsl:template>

<xsl:template match="filepath">
<span class="filepath">
<xsl:apply-templates/>
</span>    
</xsl:template>

<xsl:template match="xref">
<xsl:apply-templates/> 
</xsl:template>

<xsl:template match="info">
<div>
<xsl:apply-templates/>
</div>    
</xsl:template>

<xsl:template match="i">
<em>
<xsl:apply-templates/>
</em>    
</xsl:template>








<!-- Add both lang and xml:lang attributes -->
<xsl:template match="@xml:lang" name="generate-lang">
<xsl:param name="lang" select="."/>
<xsl:attribute name="xml:lang">
<xsl:value-of select="$lang"/>
</xsl:attribute>
<xsl:attribute name="lang">
<xsl:value-of select="$lang"/>
</xsl:attribute>
</xsl:template>




</xsl:stylesheet>

then changed the xsl named map2htmtocImpl.xsl template named as generate-toc in xslhtml\map2htmtoc folder as like this

template changes only done

<xsl:template name="generate-toc">
<html style="overflow-y:auto"><xsl:value-of select="$newline"/>
<head><xsl:value-of select="$newline"/><title>Configuring Workflow</title><xsl:value-of select="$newline"/>
<xsl:value-of select="$newline"/>
<xsl:call-template name="generateDefaultCopyright"/>
<xsl:call-template name="generateCharset"/>
<xsl:if test="string-length($contenttarget)>0 and
            $contenttarget!='NONE'">
<base target="{$contenttarget}"/>
<xsl:value-of select="$newline"/>
</xsl:if>
<!-- initial meta information -->
<!-- Set the character set to UTF-8 -->
<!-- Generate a default copyright, if needed -->
<xsl:call-template name="generateDefaultMeta"/> <!-- Standard meta for security, robots, etc -->
<xsl:call-template name="copyright"/>         <!-- Generate copyright, if specified manually -->
<xsl:call-template name="generateCssLinks"/>  <!-- Generate links to CSS files -->
<xsl:call-template name="generateMapTitle"/> <!-- Generate the <title> element -->
<xsl:call-template name="gen-user-head" />    <!-- include user's XSL HEAD processing here -->
<xsl:call-template name="gen-user-scripts" /> <!-- include user's XSL javascripts here -->
<xsl:call-template name="gen-user-styles" />  <!-- include user's XSL style element and content here -->
</head><xsl:value-of select="$newline"/>

<body>
<xsl:if test="string-length($OUTPUTCLASS) &gt; 0">
<xsl:attribute name="class">
<xsl:value-of select="$OUTPUTCLASS"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="$newline"/>
<nav><xsl:value-of select="$newline"/>
<div xmlns:glossdata="http://dita4publishers.org/glossdata" xmlns:mapdriven="http://dita4publishers.org/mapdriven" xmlns:enum="http://dita4publishers.org/enumerables" class="dynamic-toc"><xsl:value-of select="$newline"/>
<div id="container" ><xsl:value-of select="$newline"/>
<div id="containerTop"><xsl:value-of select="$newline"/>
<div id="main"><xsl:value-of select="$newline"/>
<div id="content"><xsl:value-of select="$newline"/>
<form name="mainForm" action="javscript:;"><xsl:value-of select="$newline"/>
<div class="newsItem"><xsl:value-of select="$newline"/>
<div id="expandcontractdiv"><xsl:value-of select="$newline"/>
<a href="javascript:tree.expandAll()" class="treetools">Expand all</a><xsl:value-of select="$newline"/>
<a href="javascript:tree.collapseAll()" class="treetools">Collapse all</a><xsl:value-of select="$newline"/>
</div><xsl:value-of select="$newline"/>
<div id="treeDiv1"> </div><xsl:value-of select="$newline"/>
</div><xsl:value-of select="$newline"/>
</form><xsl:value-of select="$newline"/>
</div><xsl:value-of select="$newline"/>
</div><xsl:value-of select="$newline"/>
</div><xsl:value-of select="$newline"/>
</div><xsl:value-of select="$newline"/>
</div><xsl:value-of select="$newline"/>
<xsl:apply-templates/>
</nav><xsl:value-of select="$newline"/>
<iframe class="contentwin" id="contentwin" name="contentwin" src="test.html"> 
</iframe><xsl:value-of select="$newline"/>
<div id="footer" class="footer"></div><xsl:value-of select="$newline"/>
<script xmlns:glossdata="http://dita4publishers.org/glossdata" xmlns:mapdriven="http://dita4publishers.org/mapdriven" xmlns:enum="http://dita4publishers.org/enumerables" type="text/javascript" src="yahoo.js"> </script><xsl:value-of select="$newline"/>
<script xmlns:glossdata="http://dita4publishers.org/glossdata" xmlns:mapdriven="http://dita4publishers.org/mapdriven" xmlns:enum="http://dita4publishers.org/enumerables" type="text/javascript" src="event.js"> </script><xsl:value-of select="$newline"/>
<script xmlns:glossdata="http://dita4publishers.org/glossdata" xmlns:mapdriven="http://dita4publishers.org/mapdriven" xmlns:enum="http://dita4publishers.org/enumerables" type="text/javascript" src="treeview.js"> </script><xsl:value-of select="$newline"/>
</body><xsl:value-of select="$newline"/>
</html>
</xsl:template>

then I have run integrator.xml command ant -f integrator.xml in command prompt after that i have run the transformation named xhtml-custom in oxygen then I am getting the transformation successful but oxygen showing some error as shown below

System ID: E:\task\Test.ditamap
Scenario: Test (xhtml-common)
Input file: E:\task\Test.ditamap
Engine name: DITA-OT
Severity: error
Description: Ambiguous rule match for /task/taskbody[1]/steps[1]/step[3]/cmd[1]/image[1]

System ID: E:\task\Test.ditamap
Scenario: Test (xhtml-common)
Input file: E:\task\Test.ditamap
Engine name: DITA-OT
Severity: error
Description: Ambiguous rule match for /task/taskbody[1]/steps[1]/step[6]/info[1]/image[1]

System ID: E:\task\Test.ditamap
Scenario: Test (xhtml-common)
Input file: E:\task\Test.ditamap
Engine name: DITA-OT
Severity: error
Description: Ambiguous rule match for /task/taskbody[1]/steps[1]/step[7]/stepresult[1]/image[1]

System ID: E:\task\Test.ditamap
Scenario: Test (xhtml-common)
Input file: E:\task\Test.ditamap
Engine name: DITA-OT
Severity: error
Description: Ambiguous rule match for /task/taskbody[1]/steps[1]/step[9]/info[1]/image[1]

System ID: E:\task\Test.ditamap
Scenario: Test (xhtml-common)
Input file: E:\task\Test.ditamap
Engine name: DITA-OT
Severity: error
Description: Ambiguous rule match for /task/taskbody[1]/steps[1]/step[8]/info[1]/image[1]

System ID: E:\task\Test.ditamap
Scenario: Test (xhtml-common)
Input file: E:\task\Test.ditamap
Engine name: DITA-OT
Severity: error
Description: Ambiguous rule match for /task/taskbody[1]/steps[1]/step[12]/cmd[1]/image[1]

and the index.html which is created by the transform template changes not applying

Please assist me on this issue


回答1:


You seem to have two use cases: 1) Customize the HTML output produced for each topic. 2) Customize the HTML output produced for the index.html table of contents.

By answer will be mostly about (1). Once in your plugin.xml you add this extension:

<feature extension="dita.xsl.xhtml" file="xslhtml/dita2xhtml.xsl"/>

your custom "dita2xhtml.xsl" will be contributed as an XSLT customization stylesheet to all the XHTML-based outputs. So the extension will not be limited to your custom transtype, even the base XHTML output will use your XSLT changes. Your custom "dita2xhtml.xsl" will not be the main XSLT stylesheet in the transformation, but the xsl:templates you write in it will take precedence over the ones in the base XSLT stylesheets. So your custom "dita2xhtml.xsl" should not contain imports to other XSLT stylesheets like "dita2html-base.xsl" which you probably copied from the base XHTML plugin, it should just contain the xsl:templates which override the base processing. Your custom XSLT processing will be applied when DITA topics are converted to equivalent HTML files.

If you also want to influence how the index.html (table of contents) is generated there is another plugin extension called "dita.xsl.htmltoc" which you can declare in the plugin.xml and have it point to another custom XSLT stylesheet which will override templates specified in the base XHTML plugin for the TOC processing.

But as I mentioned both the "dita.xsl.xhtml" and "dita.xsl.htmltoc" extensions will be applied to all XHTML-based outputs, including to the default XHTML output.

If you want your XSLT customizations to apply only for you custom transformation type things get harder, you no longer declare the extensions in the plugin.xml but in your "build_transtype-custom.xml" instead of adding a simple antcall to the main xhtml target:

  <antcall target="dita2xhtml"/>

you would do something like:

<target name="dita2xhtml-custom">
    <echo>custom HTML transform</echo>
    <property name="args.xsl" value="${dita.plugin.com.custom.xhtml.dir}/xslhtml/dita2xhtml.xsl"/>
    <antcall target="dita2xhtml"/>
</target>

After you do that, your custom "dita2xhtml.xsl" will become the main XSLT stylesheet applied when producing the HTML file for each DITA topic. So your custom "dita2xhtml.xsl" will need to have an import to the base XHTML XSLT processing:

 <xsl:import href="plugin:org.dita.xhtml:xsl/dita2xhtml.xsl"/>


来源:https://stackoverflow.com/questions/42360542/custom-xhtml-plugin-creation-index-html-not-effecting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!