How to Use XSLT Extension Points for PDF Output from a Publishing Template
The examples in this section demonstrate how to use XSLT extension points from an Oxygen Publishing Template.
How to Style Codeblocks with a Zebra Effect
Suppose you want your codeblocks to have a particular background color for one line, and another color for the next line. One advantage of this coloring technique is that you can clearly see when text from the codeblock is wrapped.
This effect can be done by altering the HTML5 output, creating a div for
each line from the code block, then styling them.
To add this functionality using an Oxygen Publishing Template, 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 Project view, create an xslt folder inside the project root folder.
- In this folder, create an XSL file (for example, named
merged2html5Extension.xsl) with the following
content:
<?xml version="1.0" encoding="UTF-8"?> <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, ' pr-d/codeblock ')]"> <div class='zebra'> <xsl:analyze-string regex="\n" select="."> <xsl:matching-substring/> <xsl:non-matching-substring> <div><xsl:value-of select="."/></div> </xsl:non-matching-substring> </xsl:analyze-string> </div> </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.merged2html5XSLT extension point:<publishing-template> ... <pdf> ... <xslt> <extension id="com.oxygenxml.pdf.css.xsl.merged2html5" file="xslt/merged2html5Extension.xsl"/> </xslt> - Create a css folder in the publishing template directory. In this
directory, save a custom CSS file with rules that style the codeblock structure. For
example:
div.zebra { font-family:courier, fixed, monospace; white-space:pre-wrap; } div.zebra > *:nth-of-type(odd){ background-color: silver; } - Open the template descriptor file associated with your publishing template
(the .opt file) and reference your custom CSS file in the
resourceselement:<publishing-template> ... <pdf> ... <resources> <css file="css/custom.css"/> </resources> - 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.
How to Remove the Related Links Section
How to Wrap Words in Markup
Suppose you want compound words that contain hyphens (or any other criteria) to be wrapped
with inline elements (such as the HTML <code> element).
-
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 Project view, create an xslt folder inside the project root folder.
- In this folder, create an XSL file (for example, named
merged2htmlExtension.xsl) with the following
content:
<xsl:template match="text()"> <xsl:variable name="txt"> <xsl:next-match /> </xsl:variable> <xsl:analyze-string regex="(\w|\-)+" select="$txt"> <xsl:matching-substring> <!-- A word --> <xsl:choose> <xsl:when test="contains(.,'-')"> <!-- A compound word --> <code class='compound-word'><xsl:value-of select="."/></code> </xsl:when> <xsl:otherwise> <!-- A simple word --> <xsl:value-of select="." /> </xsl:otherwise> </xsl:choose> </xsl:matching-substring> <xsl:non-matching-substring> <!-- Not a word --> <xsl:value-of select="." /> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template>
- 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.merged2mergedXSLT extension point:<publishing-template> ... <pdf> ... <xslt> <extension id="com.oxygenxml.pdf.css.xsl.merged2merged" file="xslt/merged2mergedExtension.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.
How to Convert Definition Lists into Tables
Suppose you want your definitions lists (<dl>) to be displayed as
tables in your PDF output.
-
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 Project view, create an xslt folder inside the project root folder.
- In this folder, create an XSL file (for example, named
merged2html5Extension.xsl) with the following
content:
<xsl:template match="*[contains(@class, ' topic/dl ')]"> <xsl:call-template name="setaname"/> <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/> <table> <xsl:call-template name="commonattributes"/> <xsl:call-template name="setid"/> <xsl:apply-templates/> </table> <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/> </xsl:template> <xsl:template match="*[contains(@class, ' topic/dlentry ')]"> <tr> <xsl:call-template name="commonattributes"/> <xsl:call-template name="setidaname"/> <xsl:apply-templates/> </tr> </xsl:template> <xsl:template match=" *[contains(@class, ' topic/dd ')] | *[contains(@class, ' topic/dt ')]"> <td> <xsl:call-template name="commonattributes"/> <xsl:call-template name="setidaname"/> <xsl:apply-templates select="../*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/> <xsl:apply-templates/> <xsl:apply-templates select="../*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/> </td> </xsl:template>
- 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.merged2html5XSLT 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.