从dita文件中获取id以将其添加到toc.js中添加到html2插件中:
我的输入数据文件
<?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('
', '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);
如果您有任何建议,请让我阅读。
先谢谢