<?xml version="1.0" encoding="utf-8"?> <!-- Including other XML/HTML/LaTeX documents into the current one. --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Include another XML/HTML/LaTeX document into the current one. If you don't specify @type, it assumes the type of document that you're currently generating (HTML or LaTeX). LaTeX documents are simply included using \input{...}. HTML documents are a little trickier, as there's no equivalent of \input{} in HTML, plus the XSLT processor always seems to generate a DOCTYPE when producing HTML, whether you want it or not, which means that you can only really include entire HTML documents, rather than HTML fragments (maybe you can turn this off?). The workaround currently is to embed the HTML document inside an <object>. A similar argument applies for plain text documents (such as code listings) that we want to include, but are externally generated and so can't just be embedded in the source XML. @type: The type of the document to be included. [optional] Valid values are: "xml" "html" [default for HTML] "latex" [default for LaTeX] "plain" (as in text/plain) @basename: Name of file to include (including suffix!). [required] @location: Path to file to include. Note that this gets a / appended to it. However, this shouldn't make any difference in normal usage. [optional] --> <template name="include-document" match="include-document"> <common> <!-- Work out the full path specification for the file to be included = base-path + location + basename. --> <xsl:variable name="file"> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="@basename" /> </xsl:variable> </common> <common formats="/html/xhtml/"> <div> <xsl:attribute name="align"> <xsl:choose> <xsl:when test="@align"><xsl:value-of select="@align" /></xsl:when> <xsl:otherwise>left</xsl:otherwise> </xsl:choose> </xsl:attribute> <object data="{$file}"> <!-- Output text/html or text/plain as appropriate. --> <xsl:attribute name="type"> <xsl:text>text/</xsl:text> <xsl:choose> <xsl:when test="@type"><xsl:value-of select="@type" /></xsl:when> <xsl:otherwise><xsl:text>html</xsl:text></xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="width"> <xsl:choose> <xsl:when test="@width"><xsl:value-of select="@width" /></xsl:when> <xsl:otherwise><xsl:text>100%</xsl:text></xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="height"> <xsl:choose> <xsl:when test="@height"><xsl:value-of select="@height" /></xsl:when> <xsl:otherwise><xsl:text>100%</xsl:text></xsl:otherwise> </xsl:choose> </xsl:attribute> </object> </div> </common> <common formats="/latex/xelatex/"> <xsl:text>\</xsl:text> <!-- Note that input text files are currently verbatim'd in LaTeX. We may want to change this in future? --> <xsl:if test="@type = 'plain'"> <xsl:text>verbatim</xsl:text> </xsl:if> <xsl:text>input{</xsl:text> <xsl:value-of select="$file" /> <xsl:text>}</xsl:text> </common> </template> <!-- Note that including XML documents is currently problematic, as the document() function expects a valid XML document. Including XML fragments is impossible. XInclude will fix this, once it is widely supported (not yet). Best to avoid this completely for now. --> <template name="include-xml" match="include-document[@type='xml']"> <common> <xsl:variable name="file"> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="@basename" /> </xsl:variable> <xsl:apply-templates select="document($file,/)" /> </common> </template> </stylesheet>