1

要从 dita 文件中获取 id 以将其添加到 toc.js 到 html2 插件中:

我的输入 dita 文件

<?xml version="1.0" encoding="UTF-8"?>
<task id="info">
<title class="- topic/title ">Info</title>
<info class="- topic/itemgroup task/info ">
<fig id="status-wf-xsd" class="- topic/fig ">
<title class="- topic/title ">Status</title>
<image placement="inline" class="- topic/image " href="ram/raju/alias/code1_Oct31.jpg"></image>
</fig>
</info>
<info class="- topic/itemgroup task/info ">
<fig id="status-wf-xsd" class="- topic/fig ">
<title class="- topic/title ">Gnerator</title>
<image placement="inline" class="- topic/image " href="ragava/raju/alias/code1_Oct32.jpg"></image>
</fig>
</info>
</task>

我用过的xsl:dita2xhtml

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="task">
<html>
<xsl:attribute name="id">
<xsl:value-of select="attribute::id"/>
</xsl:attribute>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="info">
<div>
<span class="figcap">
<span class="enumeration fig-enumeration">Figure <xsl:number />. </span>
<xsl:value-of select="fig/title"/>
</span>
<div class="figbody">
<xsl:variable name="code" select="fig/image/@href"/>
<img xmlns="" src="img/{substring-after($code, '/alias/')}"/>
</div>  
<xsl:apply-templates/>
</div>    
</xsl:template>

<xsl:template match="image" />

<xsl:template match="fig/title" />

<xsl:template match="fig">
<div class="fignone">
<xsl:apply-templates/>
</div>    
</xsl:template>
</xsl:stylesheet>

我从dita得到的输出

<html id="info">
<title>Info</title>
<body>
<div class="fignone" id="installinfo__status-wf-jar">
<div class="figbody"> <img xmlns="" src="img/m1_Oct31.png" /> </div>
<span class="figcap"><span class="enumeration fig-enumeration">Figure 1. </span>Status</span></div>
<div>
<div class="fignone">
<div class="figbody"><img src="img/code1_Nov1.jpg"/></div>
<span class="figcap"><span class="enumeration fig-enumeration">Figure 2. </span>Gnerator</span>
</div>
</div>
</body>
</html>

对于 toc.js 生成,我在 org.dita4publishers.html2 插件中使用了名为 map2html2DynamicToc.xsl 的 xsl

模板更改

<xsl:template match="*[df:isTopicRef(.)]" mode="generate-dynamic-toc">
<xsl:param name="tocDepth" as="xs:integer" tunnel="yes" select="0"/>
<xsl:param name="parentId" as="xs:string"  tunnel="yes"/>
<xsl:param name="rootMapDocUrl" as="xs:string" tunnel="yes"/>

<xsl:if test="$tocDepth le $maxTocDepthInt">
<xsl:variable name="navPointTitle">
<xsl:apply-templates select="." mode="nav-point-title"/>      
</xsl:variable>
<xsl:variable name="topic" select="df:resolveTopicRef(.)" as="element()*"/>
<xsl:choose>
<xsl:when test="not($topic)">
<xsl:message> + [WARNING] generate-dynamic-toc: Failed to resolve topic reference to href "<xsl:sequence select="string(@href)"/>"</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="targetUri" select="htmlutil:getTopicResultUrl($outdir, root($topic), $rootMapDocUrl)" as="xs:string"/>
<xsl:variable name="relativeUri" select="relpath:getRelativePath($outdir, $targetUri)" as="xs:string"/>
<xsl:variable name="enumeration" as="xs:string?">
<xsl:apply-templates select="." mode="enumeration"/>
</xsl:variable>
<xsl:variable name="self" select="generate-id(.)" as="xs:string"/>


<xsl:sequence select="concat('&#x0a;', 'var obj', $self, ' = {')"/>
<xsl:text>
label: "</xsl:text>
<xsl:sequence select="local:escapeStringforJavaScript(
if ($enumeration = '')
then normalize-space($navPointTitle)
else concat($enumeration, ' ', $navPointTitle)
)"/>
<xsl:text>",
href: "</xsl:text>
<xsl:sequence select="$relativeUri"/><xsl:text>#</xsl:text><xsl:value-of select="task/attribute::id"/>
<xsl:text>", 
target:"</xsl:text><xsl:value-of select="$contenttarget"/><xsl:text>"
};
</xsl:text>

<xsl:call-template name="makeJsTextNode">
<xsl:with-param name="linkObjId" select="$self"/>
<xsl:with-param name="parentId" select="$parentId" tunnel="yes"/>
</xsl:call-template>

<!-- Any subordinate topics in the currently-referenced topic are
reflected in the ToC before any subordinate topicrefs.
-->
<xsl:apply-templates mode="#current" 
select="$topic/*[df:class(., 'topic/topic')], *[df:class(., 'map/topicref')]">
<xsl:with-param name="tocDepth" as="xs:integer" tunnel="yes"
select="$tocDepth + 1"
/>
<xsl:with-param name="parentId" select="$self" as="xs:string" tunnel="yes"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>    
</xsl:if>    
</xsl:template>

但我正在使用 org.dita4publishers.html2 插件获取 toc.js 的输出

// 
// Javascript generated by HTML2 Toolkit plugin
// 
var tree;

function treeInit() {
tree = new YAHOO.widget.TreeView("treeDiv1");
var root = tree.getRoot();


var objd96e9 = {
label: " Info",
href: "Chunk820878609.html#", 
target:"contentwin"
};
var d96e9 = new YAHOO.widget.TextNode(objd96e9, root, false);



tree.draw(); 
} 

YAHOO.util.Event.addListener(window, "load", treeInit); 

但我需要使用 org.dita4publishers.html2 插件的 toc.js 输出

// 
// Javascript generated by HTML2 Toolkit plugin
// 
var tree;

function treeInit() {
tree = new YAHOO.widget.TreeView("treeDiv1");
var root = tree.getRoot();


var objd96e9 = {
label: " Info",
href: "Chunk820878609.html#info", 
target:"contentwin"
};
var d96e9 = new YAHOO.widget.TextNode(objd96e9, root, false);



tree.draw(); 
} 

YAHOO.util.Event.addListener(window, "load", treeInit);

如果您有任何建议,请让我阅读。

提前致谢

4

0 回答 0