嗨,我需要在 dita ot 插件的 xsl 文件中将变量值从一个模板调用到另一个模板:
我的 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>
我的 XSLT 模板具有所需的变量“输出类”:
<xsl:template match="*" mode="set-output-class">
<xsl:param name="default"/>
<xsl:variable name="output-class">
<xsl:apply-templates select="." mode="get-output-class"/>
</xsl:variable>
<xsl:variable name="draft-revs">
<!-- If draft is on, add revisions to default class. Simplifies processing in DITA-OT 1.6 and earlier
that created an extra div or span around revised content, just to hold @class with revs. -->
<xsl:if test="$DRAFT = 'yes'">
<xsl:for-each select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]/revprop">
<xsl:value-of select="@val"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:if>
</xsl:variable>
<xsl:variable name="using-output-class">
<xsl:choose>
<xsl:when test="string-length(normalize-space($output-class)) > 0"><xsl:value-of select="$output-class"/></xsl:when>
<xsl:when test="string-length(normalize-space($default)) > 0"><xsl:value-of select="$default"/></xsl:when>
</xsl:choose>
<xsl:if test="$draft-revs != ''">
<xsl:text> </xsl:text>
<xsl:value-of select="normalize-space($draft-revs)"/>
</xsl:if>
</xsl:variable>
<xsl:variable name="ancestry">
<xsl:if test="$PRESERVE-DITA-CLASS = 'yes'">
<xsl:apply-templates select="." mode="get-element-ancestry"/>
</xsl:if>
</xsl:variable>
<xsl:variable name="outputclass-attribute">
<xsl:apply-templates select="@outputclass" mode="get-value-for-class"/>
</xsl:variable>
<!-- Revised design with DITA-OT 1.5: include class ancestry if requested;
combine user output class with element default, giving priority to the user value. -->
<xsl:if test="string-length(normalize-space(concat($outputclass-attribute, $using-output-class, $ancestry))) > 0">
<xsl:attribute name="class">
<xsl:value-of select="$ancestry"/>
<xsl:if test="string-length(normalize-space($ancestry)) > 0 and
string-length(normalize-space($using-output-class)) > 0"><xsl:text> </xsl:text></xsl:if>
<xsl:value-of select="normalize-space($using-output-class)"/>
<xsl:if test="string-length(normalize-space(concat($ancestry, $using-output-class))) > 0 and
string-length(normalize-space($outputclass-attribute)) > 0"><xsl:text> </xsl:text></xsl:if>
<xsl:value-of select="$outputclass-attribute"/>
</xsl:attribute>
</xsl:if>
</xsl:template>
从上面的模板中,我需要将“输出类”变量获取到下面的模板中:
<xsl:template match="/*[df:class(., 'map/map')]">
<xsl:param name="doDebug" as="xs:boolean" tunnel="yes" select="false()"/>
<xsl:variable name="effectiveCoverGraphicUri" as="xs:string">
<xsl:apply-templates select="." mode="get-cover-graphic-uri"/>
</xsl:variable>
<!-- FIXME: Add mode to get effective front cover topic URI so we
can generate <guide> entry for the cover page. Also provides
extension point for synthesizing the cover if it's not
explicit in the map.
-->
<xsl:apply-templates select="." mode="report-parameters">
<xsl:with-param name="effectiveCoverGraphicUri" select="$effectiveCoverGraphicUri" as="xs:string" tunnel="yes"/>
</xsl:apply-templates>
<xsl:variable name="graphicMap" as="element()">
<xsl:apply-templates select="." mode="generate-graphic-map">
<xsl:with-param name="effectiveCoverGraphicUri" select="$effectiveCoverGraphicUri" as="xs:string" tunnel="yes"/>
<xsl:with-param name="uplevels" select="$uplevels" as="xs:string" tunnel="yes" />
</xsl:apply-templates>
</xsl:variable>
<xsl:message> + [INFO] Collecting data for index generation, enumeration, etc....</xsl:message>
<xsl:variable name="collected-data" as="element()">
<xsl:call-template name="mapdriven:collect-data"/>
</xsl:variable>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] Writing file <xsl:sequence select="relpath:newFile($outdir, 'collected-data.xml')"/>...</xsl:message>
<xsl:result-document href="{relpath:newFile($outdir, 'collected-data.xml')}"
format="indented-xml"
>
<xsl:sequence select="$collected-data"/>
</xsl:result-document>
</xsl:if>
<xsl:result-document href="{relpath:newFile($outdir, 'graphicMap.xml')}" format="graphic-map"
>
<xsl:sequence select="$graphicMap"/>
</xsl:result-document>
<xsl:call-template name="make-meta-inf"/>
<xsl:call-template name="make-mimetype"/>
<xsl:message> + [INFO] Gathering index terms...</xsl:message>
<xsl:apply-templates select="." mode="generate-content">
<xsl:with-param name="collected-data" as="element()" select="$collected-data" tunnel="yes"/>
</xsl:apply-templates>
<xsl:if test="$epubtrans:isEpub3">
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] generating EPUB3 nav</xsl:message>
</xsl:if>
<xsl:apply-templates select="." mode="epubtrans:generate-nav">
<xsl:with-param name="collected-data" as="element()" select="$collected-data" tunnel="yes"/>
</xsl:apply-templates>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] after generate-nav</xsl:message>
</xsl:if>
</xsl:if>
<!-- NOTE: The generate-toc mode is for the EPUB2 toc.ncx, not the HTML toc -->
<xsl:if test="$epubtrans:isEpub2 or $epubtrans:isDualEpub">
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] generating EPUB2 toc.ncx...</xsl:message>
</xsl:if>
<xsl:apply-templates select="." mode="generate-toc">
<xsl:with-param name="collected-data" as="element()" select="$collected-data" tunnel="yes"/>
</xsl:apply-templates>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] after generate-toc</xsl:message>
</xsl:if>
</xsl:if>
<xsl:apply-templates select="." mode="generate-index">
<xsl:with-param name="collected-data" as="element()" select="$collected-data" tunnel="yes"/>
</xsl:apply-templates>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] after generate-index</xsl:message>
</xsl:if>
<xsl:apply-templates select="." mode="generate-book-lists">
<xsl:with-param name="collected-data" as="element()" select="$collected-data" tunnel="yes"/>
</xsl:apply-templates>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] after generate-book-lists</xsl:message>
</xsl:if>
<xsl:apply-templates select="." mode="generate-opf">
<xsl:with-param name="graphicMap" as="element()" tunnel="yes" select="$graphicMap"/>
<xsl:with-param name="collected-data" as="element()" select="$collected-data" tunnel="yes"/>
<xsl:with-param name="effectiveCoverGraphicUri" select="$effectiveCoverGraphicUri" as="xs:string" tunnel="yes"/>
</xsl:apply-templates>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] after generate-opf</xsl:message>
</xsl:if>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] Generating graphic copy Ant script...</xsl:message>
</xsl:if>
<xsl:apply-templates select="." mode="generate-graphic-copy-ant-script">
<xsl:with-param name="graphicMap" as="element()" tunnel="yes" select="$graphicMap"/>
</xsl:apply-templates>
<xsl:if test="$doDebug">
<xsl:message> + [DEBUG] after generate-graphic-copy-ant-script</xsl:message>
</xsl:if>
<xsl:variable name="sample"
select="relpath:newFile($outdir, 'sample.xhtml')"
as="xs:string"/>
<xsl:result-document href="{$sample}" format="html5">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>sample</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<section id="minitoc">
<ul>
<li>
<xsl:choose>
<xsl:when test="exists($outputclass = 'Ram-Files-RajRFR')">
<h1><xsl:value-of select="//topic[@outputclass='Ram-Files-RajRFR']"/></h1><hr/>
</xsl:when>
<xsl:when test="exists($outputclass = 'Files-SampletitleFST')">
<h2><xsl:value-of select="//topic[@outputclass='Ram-Files-RajRFR']"/></h2><hr/>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose></li>
</ul>
</section>
</body> </html>
</xsl:result-document>
</xsl:template>
请建议在 '/*[df:class(., 'map/map')]' 模板中获取输出类变量。
提前致谢。