length-spec
Prev | General Library Templates | Next

## length-spec

length-spec — Return a fully qualified length specification

## Description

The `length-spec` template returns the qualified length from a dimension. If an unqualified length is given, the `default.units` will be added to it.

    <xsl:template name="length-spec">
      <xsl:param name="length" select="'0pt'"></xsl:param>
      <xsl:param name="default.units" select="'px'"></xsl:param>

      <xsl:variable name="magnitude">
        <xsl:call-template name="length-magnitude">
          <xsl:with-param name="length" select="$length"></xsl:with-param>
        </xsl:call-template>
      </xsl:variable>

      <xsl:variable name="units">
        <xsl:value-of select="substring($length, string-length($magnitude)+1)"></xsl:value-of>
      </xsl:variable>

      <xsl:value-of select="$magnitude"></xsl:value-of>
      <xsl:choose>
        <xsl:when test="$units='cm'                     or $units='mm'                     or $units='in'                     or $units='pt'                     or $units='pc'                     or $units='px'                     or $units='em'">
          <xsl:value-of select="$units"></xsl:value-of>
        </xsl:when>
        <xsl:when test="$units = ''">
          <xsl:value-of select="$default.units"></xsl:value-of>
        </xsl:when>
        <xsl:otherwise>
          <xsl:message>
            <xsl:text>Unrecognized unit of measure: </xsl:text>
            <xsl:value-of select="$units"></xsl:value-of>
            <xsl:text>.</xsl:text>
          </xsl:message>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

Prev | Up | Next
length-units | Home | length-in-points