Изменение имен файлов темы xhtml в выводе epub с помощью плагина DITA OT Epub - PullRequest
0 голосов
/ 17 мая 2018

Мне нужно изменить имена файлов тем в выходных данных EPUB с помощью плагина EPUB DITA OT:

Мой файл Ditamap:

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

Мой файл topic_1.dita

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

Мой файл topic_2.dita

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

Для изменения имени файла с помощью приведенных ниже шаблонов, которые есть в плагине DITA OT EPUB

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

Выходные имена файлов темы вВыходные данные EPUB я получаю как "topic_1_d76.xhtml", "topic_2_d77.xhtml" и т. д. ... Но мне нужно название темы в качестве имени файла в выходных данных EPUB "Ram_Files_Raj_RFR.xhtml", "Files_Sampletitle_FST.xhtml".

Пожалуйста, предложите мне этот вопрос.

Заранее спасибо

1 Ответ

0 голосов
/ 18 мая 2018

Функция htmlutil: getResultTopicBaseName () генерирует имя файла для HTML-файлов результатов, созданных из тем.

Эта функция использует шаблоны в режиме get-result-topic-base-name (если вы явно не включили стратегию организации файлов с одним каталогом), базовая реализация которой:

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

Который по умолчанию просто использует значение @ copy-to или @href.

Вы можете переопределить этот шаблон, чтобы делать то, что вы хотите, например, использовать заголовок темы.

Другой вариант, если вы используете OT 1.8.5, - расширить плагин Adjust Copy-to, чтобы в атрибуте @ copy-to указывались нужные вам имена файлов. Это приводит к применению этих имен файлов к любому процессу OT, не только к EPUB, но требует, чтобы вы использовали специфичную для D4P настройку предварительной обработки, которая используется преобразованиями, предоставляемыми D4P (EPUB, D4P HTML2, D4P HTML5).

Плагин Adjust Copy-to (в настоящее время) не работает с 2.x и 3.x Open Toolkit, потому что предварительная обработка была в значительной степени переписана, и у меня не было возможности обновить плагин EPUB. В настоящее время я работаю над обновлением преобразования EPUB для работы с OT 2.5.4 и 3.x.

...