I need to change the topic file names in the EPUB output using EPUB DITA OT plugin:
My Ditamap file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pubmap
PUBLIC "urn:pubid:com.sam.doctypes:dita:pubmap" "pubmap.dtd">
<pubmap xml:lang="en-US">
<pubtitle>
<mainpubtitle outputclass="book">Sample Word</mainpubtitle>
</pubtitle>
<topicref href="topics/topic_1.dita">
<topicmeta>
<navtitle>Ram-Files-Raj (RFR)</navtitle>
<metadata/>
</topicmeta>
</topicref>
<topicref href="topics/topic_2.dita">
<topicmeta>
<navtitle>Files-Sampletitle (FST)</navtitle>
<metadata/>
</topicmeta>
</topicref>
</pubmap>
My topic_1.dita file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "urn:pubid:com.sam.doctypes:dita:topic" "topic.dtd">
<topic id="topic_1" xml:lang="en-US" outputclass="Ram-Files-RajRFR"><title>Ram-Files-Raj (RFR)</title></topic>
My topic_2.dita file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "urn:pubid:com.sam.doctypes:dita:topic" "topic.dtd">
<topic id="topic_2" xml:lang="en-US" outputclass="Files-SampletitleFST"><title>Files-Sampletitle (FST)</title></topic>
For changing the file name using these below templates which are in DITA OT EPUB plugin
<xsl:template match="*[df:class(., 'topic/topic')]" mode="generate-content">
<xsl:param name="doDebug" as="xs:boolean" tunnel="yes" select="false()"/>
<!-- This template generates the output file for a referenced topic.
-->
<!-- The topicref that referenced the topic -->
<xsl:param name="topicref" as="element()?" tunnel="yes"/>
<!-- Result URI to which the document should be written. -->
<xsl:param name="resultUri" as="xs:string" tunnel="yes"/>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] generate-content: handling topic <xsl:value-of select="name(.)"/>...</xsl:message>
<xsl:message> + [DEBUG] generate-content: Generating base HTML using default-mode HTML generation....</xsl:message>
</xsl:if>
<xsl:variable name="htmlNoNamespace" as="node()*">
<xsl:apply-templates select="." mode="map-driven-content-processing">
<xsl:with-param name="topicref" select="$topicref" as="element()?" tunnel="yes"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] generate-content: Generating XHTML from base HTML...</xsl:message>
</xsl:if>
<xsl:variable name="xhtml" as="node()*">
<xsl:apply-templates select="$htmlNoNamespace" mode="html2xhtml">
<xsl:with-param name="topicref" select="$topicref" as="element()?" tunnel="yes"/>
<xsl:with-param name="resultUri" as="xs:string" tunnel="yes" select="$resultUri"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] xhtml:
<xsl:sequence select="$xhtml"/></xsl:message>
</xsl:if>
<xsl:message> + [INFO] Writing topic <xsl:value-of select="$topicref/@href"/> to HTML file "<xsl:sequence select="$resultUri"/>"...</xsl:message>
<xsl:result-document format="html5"
href="{$resultUri}"
exclude-result-prefixes="opf">
<xsl:sequence select="$xhtml"/>
</xsl:result-document>
</xsl:template>
<xsl:template match="*[df:isTopicRef(.)]" mode="generate-content">
<xsl:param name="doDebug" as="xs:boolean" tunnel="yes" select="false()"/>
<xsl:param name="rootMapDocUrl" as="xs:string" tunnel="yes"/>
<!-- <xsl:variable name="doDebug" as="xs:boolean" select="true()"/>-->
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] Handling topicref to "<xsl:sequence select="string(@href)"/>" in mode generate-content</xsl:message>
</xsl:if>
<xsl:variable name="topic" select="df:resolveTopicRef(.)" as="element()*"/>
<xsl:choose>
<xsl:when test="not($topic)">
<xsl:message> + [WARNING] generate-content: Failed to resolve topic reference to href "<xsl:sequence select="string(@href)"/>"</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="topicResultUri"
select="htmlutil:getTopicResultUrl($outdir, root($topic), $rootMapDocUrl, $doDebug)"
as="xs:string"
/>
<!-- Do href fixup before doing full default-mode processing: -->
<xsl:variable name="tempTopic" as="document-node()">
<xsl:document>
<xsl:apply-templates select="$topic" mode="href-fixup">
<xsl:with-param name="topicResultUri" select="$topicResultUri"
tunnel="yes"/>
<xsl:with-param name="topicref" as="element()" select="." tunnel="yes"/>
</xsl:apply-templates>
</xsl:document>
</xsl:variable>
<!-- Apply templates in default mode to the topic with fixed up hrefs: -->
<xsl:apply-templates select="$tempTopic" mode="#current">
<xsl:with-param name="topicref" as="element()" select="." tunnel="yes"/>
<xsl:with-param name="resultUri" select="$topicResultUri"
tunnel="yes"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The out put topic file names in epub output i am getting as "topic_1_d76.xhtml", "topic_2_d77.xhtml", so on... But i need topic title as file name in the epub output "Ram_Files_Raj_RFR.xhtml", "Files_Sampletitle_FST.xhtml".
Please suggest me on this issue.
Thanks in Advance
The function htmlutil:getResultTopicBaseName() generates the filename for result HTML files generated from topics.
This function uses templates in the mode get-result-topic-base-name (if you haven't explicitly turned on the single-dir file organization strategy), the base implementation of which is:
<xsl:template match="/" mode="get-result-topic-base-name">
<xsl:param name="topicref" tunnel="yes" as="element()?"/>
<xsl:param name="topicUri" as="xs:string"/>
<!-- Default template for organizational strategies other than single-dir -->
<xsl:variable name="baseName" as="xs:string">
<xsl:choose>
<xsl:when test="string($topicref/@copy-to) != ''">
<xsl:sequence select="relpath:getNamePart($topicref/@copy-to)"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="relpath:getNamePart($topicUri)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:sequence select="$baseName"/>
</xsl:template>
Which by default just uses the @copy-to or @href value.
You can override this template to do what you want, e.g., use the title of the topic.
Another option, if you're using OT 1.8.5, is to extend the Adjust Copy-to plugin to set the @copy-to attribute to the filenames you want. This has the effect of applying those filenames to any OT process, not just the EPUB, but requires that you use the D4P-specific preprocessing customization, which is used by the D4P-provided transforms (EPUB, D4P HTML2, D4P HTML5).
The Adjust Copy-to plugin doesn't (currently) work with the 2.x and 3.x Open Toolkit because the preprocessing has been largely rewritten and I haven't had a chance to update the EPUB plugin. I'm currently working on updating the EPUB transform to work with OT 2.5.4 and 3.x.