Section 39.7 XSL 101
If you have read this far, and read carefully, you have been exposed to several key principles of writing
XSL. Basically you are creating templates which the base LaTeX conversion will “call” in exactly the right place. In a procedural language these might be called hooks. Besides a smooth integration with the rest of PreTeXt there are several advantages:
A template using a
@matchcan apply narrowly or broadly. Witness the example above for
&EXAMPLE-LIKE;. This attribute is similar to a
thispointer in an object-oriented language and the modal template is not dissimilar to a method.
PreTeXt has a discovery phase when it constructs the LaTeX preamble. If your PreTeXt source has no
<example>in it, then there will be no associated
tcolorboxstyle added to the preamble, and the LaTeX
exampleenvironment will not be defined. So the preamble is exactly what your document needs, and no more (mostly). The
@matchattribute makes this possible.
You have seen named templates, which will feel familiar if you know procedural languages. While perhaps comfortable, they are way less powerful, and we noted that we may get rid of them.
<xsl:import>mechanism allows us to keep base definitions and override others. So as you develop your style, you do not need to start from scratch.
Be aware that every single character that you put inside the
<xsl:text> element will get copied literally into the preamble of your LaTeX output, including newlines and spaces you use to indent in your XSL. Conversely, any whitespace inside your template, but between the
<xsl:text> elements is ignored. So we like to use multiple
<xsl:text> elements (except we were a bit lazy getting this out the door initially—do as we say, not as we do) and explicitly create newlines with the
character. Your goal is to have a LaTeX preamble with no blank lines and no unintended indentation. We often create comment lines (with two leading
% characters to aid with readability.
See the PreTeXt website for recommendations for books on XSL if you are encouraged to learn more.