| | <?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> |
---|
| |
---|
| | <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:value-of select="infosci:build-image-path( @location, @basename, 'print', @format )" /> |
---|
| | <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" /> |
---|
| | |
---|
| | <!-- |
---|
| | Check for existence of required attributes. For example, it doesn't really make sense for @basename to be missing. |
---|
| | --> |
---|
| | <xsl:if test="not( @basename )"> |
---|
| | <xsl:message terminate="yes"> |
---|
| | <xsl:text>ERROR: image element "</xsl:text> |
---|
| | <!-- Note that the description may be missing, which would make the error message less helpful :). --> |
---|
| | <xsl:value-of select="description" /> |
---|
| | <xsl:text>" missing required @basename attribute.</xsl:text> |
---|
| | </xsl:message> |
---|
| | </xsl:if> |
---|
| | </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:value-of select="infosci:build-image-path( @location, @basename, 'web', @format )" /> |
---|
| | </xsl:attribute> |
---|
| | |
---|
| | <xsl:attribute name="alt"> |
---|
| | <xsl:apply-templates select="description" /> |
---|
| | <xsl:if test="not( description )"> |
---|
| | <xsl:value-of select="@basename" /> |
---|
| | </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" /> |
---|
| | |
---|
| | <!-- |
---|
| | Check for existence of required attributes. For example, it doesn't really make sense for @basename to be missing. |
---|
| | --> |
---|
| | <xsl:if test="not( @basename )"> |
---|
| | <xsl:message terminate="yes"> |
---|
| | <xsl:text>ERROR: image element "</xsl:text> |
---|
| | <!-- Note that the description may be missing, which would make the error message less helpful :). --> |
---|
| | <xsl:value-of select="description" /> |
---|
| | <xsl:text>" missing required @basename attribute.</xsl:text> |
---|
| | </xsl:message> |
---|
| | </xsl:if> |
---|
| | </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:value-of select="infosci:build-image-path( @location, @basename, 'web-zoom', @format )" /> |
---|
| | </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:value-of select="infosci:build-image-path( @location, @basename, 'web', @format )" /> |
---|
| | </xsl:attribute> |
---|
| | |
---|
| | <xsl:attribute name="alt"> |
---|
| | <xsl:apply-templates select="description" /> |
---|
| | <xsl:if test="not( description )"> |
---|
| | <xsl:value-of select="@basename" /> |
---|
| | </xsl:if> |
---|
| | </xsl:attribute> |
---|
| | </img> |
---|
| | |
---|
| | <br clear="right" /> |
---|
| | <xsl:text>(Larger version)</xsl:text> |
---|
| | </a> |
---|
| | </common> |
---|
| | </template> |
---|
| | |
---|
| | |
---|
| | <!-- |
---|
| | Work out the full path specification for an image file to be included = base-path + location (if specified) + basename + suffix + format. With all arguments provided (see example values below), the result will look something like this: |
---|
| | /base/path/images/an_image-print.pdf |
---|
| | /base/path/images/an_image-web.png |
---|
| | |
---|
| | $base-path is a style sheet global variable; see xml2xslt.xsl. |
---|
| | |
---|
| | $location [optional]: The relative path to the image file from the current location (e.g., "images"). If not specified (empty), then this component is omitted. |
---|
| | |
---|
| | $basename: The base name of the image file, e.g., "an_image". |
---|
| | |
---|
| | $basename-suffix [optional]: Any string to append to the base name. This is usually used to distinguish the web and print versions of an image, e.g., "web" vs. "print". If not specified (empty), then this component is omitted. |
---|
| | |
---|
| | $format [optional]: The suffix for the image file, e.g., "png" or "pdf". If not specified (empty), then the global default suffix ($image-format) is used. |
---|
| | --> |
---|
| | <function name="infosci:build-image-path" as="xs:string"> |
---|
| | <common> |
---|
| | <xsl:param name="location" /> |
---|
| | <xsl:param name="basename" /> |
---|
| | <xsl:param name="basename-suffix" /> |
---|
| | <xsl:param name="format" /> |
---|
| | |
---|
| | <xsl:sequence select="concat( $base-path, |
---|
| | '/', |
---|
| | if ( string-length( $location ) > 0 ) |
---|
| | then concat( $location, '/') |
---|
| | else '', |
---|
| | $basename, |
---|
| | if ( string-length( $basename-suffix ) > 0 ) |
---|
| | then concat( '-', $basename-suffix ) |
---|
| | else '', |
---|
| | '.', |
---|
| | if ( string-length( $format ) > 0 ) |
---|
| | then $format |
---|
| | else $image-format )" /> |
---|
| | </common> |
---|
| | </function> |
---|
| | |
---|
| | |
---|
| | </stylesheet> |
---|
| | |
---|