overriding a template in dita2xhtml.xsl

Post here questions and problems related to editing and publishing DITA content.
urbanrobots
Posts: 86
Joined: Sun May 03, 2015 7:34 pm
Location: San Francisco

overriding a template in dita2xhtml.xsl

Post by urbanrobots »

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?

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>
Thank you for your time. I haven't started to investigate how to get the keyword to render correctly.

Nicholas
urbanrobots
Posts: 86
Joined: Sun May 03, 2015 7:34 pm
Location: San Francisco

Re: overriding a template in dita2xhtml.xsl

Post by urbanrobots »

Hi again -

Okay, it looks like the $displaytext variable definition wasn't doing what I thought. The variable was receiving a value only for abbreviated-form elements and not for term elements.

I updated the $displaytext variable definition, as follows:

Code: Select all

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

<!-- ### old when statement ### -->
<!-- <xsl:when test="normalize-space(.) != ''">
<xsl:apply-templates select="." mode="dita-ot:text-only"/>
</xsl:when>-->

<!-- ### new otherwise statement ### -->
<xsl:otherwise>
<xsl:apply-templates select="." mode="output-term"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Adding that new otherwise statement seemed to do the trick...

Nicholas
urbanrobots
Posts: 86
Joined: Sun May 03, 2015 7:34 pm
Location: San Francisco

Re: overriding a template in dita2xhtml.xsl

Post by urbanrobots »

Hi folks - Can you tell me where the keyword template is defined? I'm having difficulty finding where to override this so that I can insert the logic to capitalize the first letter of the node value.

Thanks for your time.
Nicholas
Radu
Posts: 9446
Joined: Fri Jul 09, 2004 5:18 pm

Re: overriding a template in dita2xhtml.xsl

Post by Radu »

Hi Nicholas,

In the XSLT stylesheet:

DITA-OT-DIR\plugins\org.dita.xhtml\xsl\xslhtml\dita2htmlImpl.xsl

there is a template like:

Code: Select all

<xsl:template match="*[contains(@class, ' topic/keyword ')]" name="topic.keyword">
..............
Usually when I want to search for a template which matches an element, I search for the last part of the element's class value, in this case topic/keyword in all the XSLTs from the DITA OT distribution using Oxygen's Find/Replace in Files tool.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply