<?xml version="1.0" encoding="utf-8"?> <!-- Image handling. Includes support for normal and "zoomed" images in HTML. TODO: Ideally, I think we should be able to define two image formats (PDF, EPS, PNG, ...) when marking up an image: one for LaTeX output, another for HTML. Mind you, if the generation of the various formats from a single master is handled outside of the XSLT processing...? --> <stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- LaTeX images are always handled the same way regardless. Image scaling factor is supported. TODO: alternatively, allow defining the scaling factor by specifying what proportion of the page width the image should occupy (a la LaTeX [width] parameter). How about a <latex-attributes> element that can be used to specify \includegraphics arguments? <width keepaspectratio="yes">0.5\columnwidth</width> <height>2cm</height> <scale>0.5</scale> etc. --> <template name="latex-image" match="image" mode="latex"> <common formats="/latex/xelatex/"> <xsl:text>\includegraphics</xsl:text> <!-- General-purpose latex pass-through arguments for \includegraphics. If providing multiple arguments, these should be comma-separated in the source XML, but do not need the enclosing square brackets. --> <xsl:if test="@latex-options"> <xsl:text>[</xsl:text> <xsl:value-of select="@latex-options" /> <xsl:text>]</xsl:text> </xsl:if> <xsl:text>{</xsl:text> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:if test="@basename"> <xsl:value-of select="@basename" /> </xsl:if> <xsl:text>-print.</xsl:text> <!-- Figure out the image format. --> <xsl:choose> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> <xsl:text>}</xsl:text> </common> </template> <!-- "Standard" scale image. For LaTeX, we simply pass off to the "latex-image" template above. TODO: if no description is given, use the basename as the content of the ALT element. TODO: can we refactor some of this into a function or something? --> <template name="normal-image" match="image[count(provide-large-version) = 0]"> <common> <!-- Check for obsolete child elements. We need to do this explicitly, as there isn't an apply-templates inside this template to pick them up automatically. --> <xsl:apply-templates select="basename|format|latex-scaling" /> </common> <common formats="/latex/xelatex/"><xsl:apply-templates select="." mode="latex" /></common> <common formats="/html/xhtml/"> <img class="padded" style="border-style: none;"> <xsl:attribute name="src"> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="basename|@basename" /> <xsl:text>-web.</xsl:text> <xsl:choose> <!-- CME: oops, I'd originally used the "format" tag to identify the format used in the LaTeX version, not the HTML! --> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="alt"><xsl:apply-templates select="description" /></xsl:attribute> </img> </common> </template> <!-- "Zoomed" image. For LaTeX, we simply pass off to the "latex-image" template above. TODO: if no description is given, use the basename as the content of the ALT element. TODO: can we refactor some of this into a function or something? --> <template name="zoomable-image" match="image[count(provide-large-version) != 0]"> <common> <!-- Check for obsolete child elements. We need to do this explicitly, as there isn't an apply-templates inside this template to pick them up automatically. --> <xsl:apply-templates select="basename|format|latex-scaling" /> </common> <common formats="/latex/xelatex/"><xsl:apply-templates select="." mode="latex" /></common> <common formats="/html/xhtml/"> <a> <xsl:attribute name="href"> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="basename|@basename" /> <xsl:text>-web-zoom.</xsl:text> <xsl:choose> <!-- CME: oops, I'd originally used the "format" tag to identify the format used in the LaTeX version, not the HTML! --> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> </xsl:attribute> <img class="padded" style="border-style: none;"> <xsl:attribute name="src"> <!-- Work out the full path specification for the file to be included = base-path + location (if specified) + basename. --> <xsl:value-of select="$base-path" /> <xsl:text>/</xsl:text> <!-- Check whether the location attribute is included. --> <xsl:if test="@location"> <xsl:value-of select="@location" /> <xsl:text>/</xsl:text> </xsl:if> <xsl:value-of select="basename|@basename" /> <xsl:text>-web.</xsl:text> <xsl:choose> <!-- CME: oops, I'd originally used the "format" tag to identify the format used in the LaTeX version, not the HTML! --> <xsl:when test="@format"> <xsl:value-of select="@format" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image-format" /> </xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:attribute name="alt"> <xsl:apply-templates select="description" /> </xsl:attribute> </img> <br clear="right" /> <xsl:text>(Larger version)</xsl:text> </a> </common> </template> </stylesheet>