How to Remove Links from Terms
Your topics might contain multiple references to the same <term>
.
These terms can further be explained in the glossary. In this case, you may want to only keep
the first occurrence of this term to be a link to the glossary and display the other terms as
text.
To add this functionality, use an Oxygen Publishing Template and follow these
steps:
- If you have not already created a Publishing Template, you need to create one. For details, see How to Create a Publishing Template.
- Link the folder associated with the publishing template to your current project in the Project view.
- Using the view, create an xslt folder inside the project root folder.
- In the newly created folder, create an XSL file (for example, named
merged2html5Extension.xsl) with the following
content:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="*[contains(@class, ' topic/term ')]" name="topic.term"> <!-- Save the current @href value --> <xsl:variable name="current-href" select="@href"/> <!-- Get the closest parent topic --> <xsl:variable name="closest-parent" select="ancestor::*[contains(@class, ' topic/topic ')][1]"/> <!-- Get the first <term> having the same href --> <xsl:variable name="first-term-with-same-href" select="($closest-parent// *[contains(@class, ' topic/term ')][@href=$current-href])[1]"/> <!-- Call the HTML5 default template --> <xsl:variable name="result"> <xsl:next-match/> </xsl:variable> <!-- Call the copy template that will remove the links --> <xsl:apply-templates select="$result" mode="remove-extra-links"> <xsl:with-param name="is-first-term-with-same-href" select="generate-id(.) = generate-id($first-term-with-same-href)" tunnel="yes"/> </xsl:apply-templates> </xsl:template> <xsl:template match="node() | @*" mode="remove-extra-links"> <xsl:copy> <xsl:apply-templates select="node() | @*" mode="#current"/> </xsl:copy> </xsl:template> <xsl:template match="a" mode="remove-extra-links"> <xsl:param name="is-first-term-with-same-href" tunnel="yes"/> <xsl:choose> <!-- Process the first term as a link --> <xsl:when test="$is-first-term-with-same-href"> <xsl:next-match/> </xsl:when> <xsl:otherwise> <!-- Process the other terms as text --> <xsl:copy-of select="child::*"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
- Open the template descriptor file associated with your publishing
template (the .opt file) and set the XSLT stylesheet created in the previous
step with the
com.oxygenxml.pdf.css.xsl.merged2html5
XSLT extension point:<publishing-template> ... <pdf> ... <xslt> <extension id="com.oxygenxml.pdf.css.xsl.merged2html5" file="xslt/merged2html5Extension.xsl"/> </xslt>
- Edit the DITA Map PDF - based on HTML5 & CSS transformation scenario.
- In the Templates tab, click the Choose Custom Publishing Template link and select your template.
- Click OK to save the changes and run the transformation scenario.