0

我已经创建了这样的自定义 xhtml 插件

我的 plugin.xml 代码是

<?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 代码是

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

build_transtype-custom.xml 是

<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>

然后我将基本插件 xsl 文件夹粘贴到自定义插件中,我更改了名为 dita2xhtml.xsl 的 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>

然后像这样在 xslhtml\map2htmtoc 文件夹中更改名为 map2htmtocImpl.xsl 的模板,名为 generate-toc

仅完成模板更改

<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>

然后我在命令提示符中运行了 integrator.xml 命令 ant -f integrator.xml 之后我在氧气中运行了名为 xhtml-custom 的转换然后我得到了成功的转换但是氧气显示了一些错误,如下所示

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]

并且由转换模板创建的 index.html 更改不适用

请在这个问题上帮助我

4

1 回答 1

2

您似乎有两个用例:1)自定义为每个主题生成的 HTML 输出。2) 自定义为 index.html 目录生成的 HTML 输出。

答案主要是关于(1)。在您的 plugin.xml 中添加此扩展名后:

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

您的自定义“dita2xhtml.xsl”将作为 XSLT 自定义样式表提供给所有基于 XHTML 的输出。因此,扩展将不限于您的自定义转换,甚至基本 XHTML 输出也将使用您的 XSLT 更改。您的自定义“dita2xhtml.xsl”将不是转换中的主要 XSLT 样式表,但您在其中编写的 xsl:templates 将优先于基本 XSLT 样式表中的那些。因此,您的自定义“dita2xhtml.xsl”不应包含对其他 XSLT 样式表的导入,例如您可能从基本 XHTML 插件复制的“dita2html-base.xsl”,它应该只包含覆盖基本处理的 xsl:templates。当 DITA 主题转换为等效的 HTML 文件时,将应用您的自定义 XSLT 处理。

如果您还想影响 index.html(目录)的生成方式,还有另一个名为“dita.xsl.htmltoc”的插件扩展,您可以在 plugin.xml 中声明它并让它指向另一个自定义 XSLT 样式表将覆盖在基本 XHTML 插件中为 TOC 处理指定的模板。

但正如我提到的,“dita.xsl.xhtml”和“dita.xsl.htmltoc”扩展名都将应用于所有基于 XHTML 的输出,包括默认的 XHTML 输出。

如果您希望您的 XSLT 自定义仅适用于您的自定义转换类型,事情会变得更加困难,您不再在 plugin.xml 中而是在“build_transtype-custom.xml”中声明扩展,而不是向主 xhtml 目标添加简单的 antcall :

  <antcall target="dita2xhtml"/>

你会做这样的事情:

<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>

之后,您的自定义“dita2xhtml.xsl”将成为为每个 DITA 主题生成 HTML 文件时应用的主要 XSLT 样式表。因此,您的自定义“dita2xhtml.xsl”将需要导入基本 XHTML XSLT 处理:

 <xsl:import href="plugin:org.dita.xhtml:xsl/dita2xhtml.xsl"/>
于 2017-02-22T12:03:08.350 回答