This article mainly introduces an example of how to use XSLT as HTML style sheet. The code shown in the article provides a download link at the end of the full text. If you need it, please refer to the following introduction
When you hear the word stylesheet, you may think of CSS stylesheets. XSLT stylesheets are often used for XML transformations, such as mapping data between web services. Because XSLT is very suitable for this purpose, the <xsl:transform> alias for the top-level element <stylesheet> is created, although this is rarely used. The input structure of this XSLT conversion is very different from the output structure. Most importantly, the difference in namespaces.
The input structure of an XSLT style sheet is similar to that of an output structure, but is simpler. Some markers have been expanded, but most of them are just copied to the output as is. The namespaces of input and output are the same (HTML). The input document can also contain stylesheet directives (such as creating footnotes) that belong to another namespace and are not passed into the output.
Common abbreviations
CSS: Cascading Style Sheet
XHTML: Extensible Hypertext Markup Language
XPath: XML Path Language
XSLT: Extensible Stylesheet Language Conversion
In this article, we will learn how to augment XHTML documentation using XSLT stylesheets. The examples in the article show how to use directives, how to reference sections of other source documents, and how to use links to navigate in the main document. In addition, we explored the difference between interpretation and compilation of pages.
Limitations of CSS Stylesheets
XSLT stylesheets do not prevent you from using other technologies, such as JavaScript or CSS. CSS is suitable for fonts, bolding, colors, spacing, etc. It is not suitable for combining information from different locations, such as footnotes, modules, or generating a directory. This is where XSLT comes in, it complements rather than replaces CSS.
XSLT usage examples
In fact, you can centralize the XSLT code in one file. For simplicity, each example in this article is located in a separate XSLT file, except for some necessary code. Listing 1 gives the required code.
Listing 1. Required code (located in samples/common.xml) XML/HTML Code Copy content to clipboard