How to Use XSLT Extension Points for PDF Output from a DITA-OT PluginEdit online
These examples demonstrate how to use XSLT extension points from a DITA-OT plugin.
Use-Case 1: Styling Codeblocks with a Zebra EffectEdit online
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 a DITA-OT plugin, follow these steps:
- In the DITA-OT-DIR\plugins\ folder, create a folder for this plugin (for example, com.oxygenxml.pdf.custom.codeblocks).
- Create a plugin.xml file (in the folder you created in step 1) that specifies the
extension point and your customization stylesheet. For
example:
<plugin id="com.oxygenxml.pdf.custom.codeblocks"> <feature extension="com.oxygenxml.pdf.css.xsl.merged2html5" file="custom_codeblocks.xsl"/> </plugin>
- Create your customization stylesheet (for example, custom_codeblocks.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>
- Use the Run DITA-OT Integrator transformation scenario found in the DITA Map section in the Configure Transformation Scenario(s) dialog box.
- Create 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; } - Edit a DITA Map PDF - based on HTML5 & CSS transformation scenario and
reference your custom CSS file (using the
args.cssparameter). - Run the transformation scenario.
Use-Case 2: Removing the Related Links SectionEdit online
Suppose you want the related links sections to be removed from the PDF output.
To add this functionality using a DITA-OT plugin, follow these steps:
- In the DITA-OT-DIR\plugins\ folder, create a folder for this plugin (for example, com.oxygenxml.pdf.custom.codeblocks).
- Create a plugin.xml file (in the folder you created in step 1) that specifies
the extension point and your customization stylesheet. For
example:
<plugin id="com.oxygenxml.pdf.custom.related.links"> <feature extension="com.oxygenxml.pdf.css.xsl.merged2merged" file="custom_related_links.xsl"/> </plugin>
- Create your customization stylesheet (for example, custom_related_links.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, ' topic/related-links ')]"> <!-- Remove. --> </xsl:template> </xsl:stylesheet>
- Use the Run DITA-OT Integrator transformation scenario found in the DITA Map section in the Configure Transformation Scenario(s) dialog box.
- Run the DITA Map PDF - based on HTML5 & CSS transformation scenario.