overriding a template in dita2xhtml.xsl
Posted: Thu Jul 07, 2016 9:01 pm
Hi.
Disclaimer:: I'm probably approaching this in the wrong way.
We use keys for keyword, abbreviated-form, and term elements. However, sometimes these keys appear at the start of a sentence.
We have created an @outputclass (cap_first_letter) to identify when the first letter of an element should be capitalized. We have this working the PDF transform but not in the Oxygen Webhelp transform.
While the abbreviated-form element seems to work okay, which we don't really care about, the term element does not render correctly. I could only find the topic.term template in the dita2xhtml.xsl file. Is there another template someplace that should be updated instead?
Thank you for your time. I haven't started to investigate how to get the keyword to render correctly.
Nicholas
Disclaimer:: I'm probably approaching this in the wrong way.
We use keys for keyword, abbreviated-form, and term elements. However, sometimes these keys appear at the start of a sentence.
We have created an @outputclass (cap_first_letter) to identify when the first letter of an element should be capitalized. We have this working the PDF transform but not in the Oxygen Webhelp transform.
While the abbreviated-form element seems to work okay, which we don't really care about, the term element does not render correctly. I could only find the topic.term template in the dita2xhtml.xsl file. Is there another template someplace that should be updated instead?
Code: Select all
<!-- Note: processing for the term specialization abbreviated-form is located in abbrev-d.xsl. -->
<xsl:key name="keyref" match="*[contains(@class, ' topic/term ')]" use="@keyref"/>
<xsl:key name="abbrev_keyref" match="*[contains(@class,' abbrev-d/abbreviated-form ')]" use="@keyref"/>
<!-- terms and abbreviated-forms -->
<xsl:template match="*[contains(@class, ' topic/term ')]" name="topic.term">
<xsl:param name="abbrev_form"/>
<xsl:variable name="hrefloc" select="@href"/>
<xsl:variable name="keys" select="@keyref"/>
<xsl:variable name="keydef" select="$keydefs//*[@keys = $keys][normalize-space(@href)]"/>
<!-- <xsl:message>Location name is <xsl:value-of
select="name(document(concat('file:///',$hrefloc))/*)"/></xsl:message>-->
<xsl:choose>
<xsl:when test="@keyref and $keydef/@href">
<xsl:variable name="target" select="$keydef/@href"/>
<xsl:variable name="updatedTarget">
<xsl:apply-templates select="." mode="find-keyref-target">
<xsl:with-param name="target" select="$target"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:variable name="entry-file-uri" select="concat($WORKDIR, $PATH2PROJ, $target)"/>
<!-- Save glossary entry file contents into a variable to workaround the infamous putDocumentCache error in Xalan -->
<xsl:variable name="entry-file-contents" select="document($entry-file-uri, /)"/>
<!-- Glossary id defined in <glossentry> -->
<xsl:variable name="glossid" select="substring-after($updatedTarget, '#')"/>
<!--
Language preference.
NOTE: glossid overrides language preference.
-->
<xsl:variable name="reflang">
<xsl:call-template name="getLowerCaseLang"/>
</xsl:variable>
<xsl:variable name="matched-target">
<xsl:call-template name="getMatchingTarget">
<xsl:with-param name="m_entry-file-contents" select="$entry-file-contents"/>
<xsl:with-param name="m_glossid" select="$glossid"/>
<xsl:with-param name="m_reflang" select="$reflang"/>
</xsl:call-template>
</xsl:variable>
<!-- End: Language preference. -->
<!-- Text should be displayed -->
<xsl:variable name="displaytext">
<xsl:choose>
<xsl:when test="$abbrev_form != ''">
<xsl:choose>
<xsl:when
test="generate-id(.) = generate-id(key('abbrev_keyref',@keyref)[1])">
<xsl:apply-templates select="." mode="getMatchingAcronym">
<xsl:with-param name="m_matched-target"
select="$matched-target"/>
<xsl:with-param name="m_keys" select="$keys"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="getMatchingAcronym">
<xsl:with-param name="m_matched-target"
select="$matched-target"/>
<xsl:with-param name="m_keys" select="$keys"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="normalize-space(.) != ''">
<xsl:apply-templates select="." mode="dita-ot:text-only"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<!-- End of displaytext -->
<!-- #### THIS IS THE LOGIC THAT UPDATES THE STRING ###-->
<xsl:variable name="displaytext">
<xsl:choose>
<xsl:when test="@outputclass = 'cap_first_letter'">
<xsl:value-of
select="translate(substring($displaytext, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
<xsl:value-of
select="substring($displaytext, 2, string-length($displaytext) - 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$displaytext"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- #### END ADDITION ###-->
<!-- hovertip text -->
<xsl:variable name="hovertext">
<xsl:apply-templates select="." mode="getMatchingGlossdef">
<xsl:with-param name="m_matched-target" select="$matched-target"/>
<xsl:with-param name="m_keys" select="$keys"/>
</xsl:apply-templates>
</xsl:variable>
<!-- End of hovertip text -->
<xsl:choose>
<xsl:when test="not(normalize-space($updatedTarget) = $OUTEXT)">
<a href="{$updatedTarget}" title="{normalize-space($hovertext)}">
<xsl:apply-templates select="." mode="output-term">
<xsl:with-param name="displaytext"
select="normalize-space($displaytext)"/>
</xsl:apply-templates>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="output-term">
<xsl:with-param name="displaytext"
select="normalize-space($displaytext)"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="output-term">
<xsl:with-param name="displaytext">
<xsl:apply-templates select="." mode="dita-ot:text-only"/>
</xsl:with-param>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Nicholas