自定义XHTML插件创建index.html不起作用 [英] Custom XHTML plugin creation index.html not effecting

查看:128
本文介绍了自定义XHTML插件创建index.html不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created the custom xhtml plugin like this

我的plugin.xml代码是

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

build.xml code is

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

build_transtype-custom.xml是

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>

然后我将基本插件xsl文件夹粘贴到自定义插件,然后我将xsl更改为dita2xhtml.xsl

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>

然后在xslhtml \ map2htmtoc文件夹中将名为x2的名为map2htmtocImpl.xsl的xsl模板更改为generate-toc

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

仅完成模板更改

<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的转换,然后转换成功,但氧气显示了一些错误,如下所示

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]

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

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

在这个问题上请帮助我

推荐答案

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

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.

答案将主要是关于(1). 在plugin.xml中添加以下扩展名:

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

您的自定义"dita2xhtml.xsl"将作为XSLT自定义样式表贡献给所有基于XHTML的输出.因此,扩展名将不仅限于您的自定义转型,即使基本XHTML输出将使用您的XSLT更改. 您的自定义"dita2xhtml.xsl"将不是转换中的主要XSLT样式表,但您在其中编写的xsl:templates将优先于基本XSLT样式表中的样式表.因此,您的自定义"dita2xhtml.xsl"不应包含您可能已从基本XHTML插件复制的其他XSLT样式表(如"dita2html-base.xsl")的导入,而应仅包含xsl:templates来覆盖基本处理.将DITA主题转换为等效的HTML文件时,将应用您的自定义XSLT处理.

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.

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

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.

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

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.

如果您希望XSLT定制仅适用于您的定制转换类型,那么事情会变得更加困难,您不再在plugin.xml中声明扩展名,而是在您的"build_transtype-custom.xml"中声明扩展名,而不是向主要的xhtml目标:

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

您将执行以下操作:

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

这样做之后,在为每个DITA主题生成HTML文件时,您的自定义"dita2xhtml.xsl"将成为主要的XSLT样式表.因此,您的自定义"dita2xhtml.xsl"将需要导入到基本XHTML XSLT处理中:

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

这篇关于自定义XHTML插件创建index.html不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆