ceiling() Function |
Returns the smallest integer that is not less than the argument.
Inputs
A number. If the argument is not a number, it is transformed into a number as if it had been processed by the number() function. If the argument cannot be transformed into a number, the ceiling() function returns the value NaN (not a number).
Output
The smallest integer that is not less than the argument, or NaN if the argument cannot be converted to a number.
Defined in
XPath section 4.4, Number Functions.
Example
The following stylesheet shows the results of invoking the ceiling() function against a variety of values. We'll use this XML document as input:
    <?xml version="1.0"?>
    <report>
      <title>Miles Flown in 2001</title>
      <month sequence="01">
        <miles-flown>12379</miles-flown>
        <miles-earned>35215</miles-earned>
      </month>
      <month sequence="02">
        <miles-flown>32857</miles-flown>
        <miles-earned>92731</miles-earned>
      </month>
      <month sequence="03">
        <miles-flown>19920</miles-flown>
        <miles-earned>76725</miles-earned>
      </month>
      <month sequence="04">
        <miles-flown>18903</miles-flown>
        <miles-earned>31781</miles-earned>
      </month>
    </report>
Here's the stylesheet that uses the ceiling() function:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:months="Lookup table for month names">

      <months:name sequence="01">January</months:name>
      <months:name sequence="02">February</months:name>
      <months:name sequence="03">March</months:name>
      <months:name sequence="04">April</months:name>
      <months:name sequence="05">May</months:name>
      <months:name sequence="06">June</months:name>
      <months:name sequence="07">July</months:name>
      <months:name sequence="08">August</months:name>
      <months:name sequence="09">September</months:name>
      <months:name sequence="10">October</months:name>
      <months:name sequence="11">November</months:name>
      <months:name sequence="12">December</months:name>

      <xsl:output method="text"/>

      <xsl:variable name="newline">
    <xsl:text>
    </xsl:text>
      </xsl:variable>

      <xsl:template match="/">
        <xsl:value-of select="$newline"/>
        <xsl:text>Tests of the ceiling() function:</xsl:text>

        <xsl:value-of select="$newline"/>
        <xsl:value-of select="$newline"/>
        <xsl:text>   "ceiling('7.983')" = </xsl:text>
        <xsl:value-of select="ceiling('7.983')"/>

        <xsl:value-of select="$newline"/>
        <xsl:text>   "ceiling('-7.893')" = </xsl:text>
        <xsl:value-of select="ceiling('-7.893')"/>

        <xsl:value-of select="$newline"/>
        <xsl:text>   "ceiling(/report/month[@sequence='01']/miles-flown)" = </xsl:text>
        <xsl:value-of select="ceiling(/report/month[@sequence='01']/miles-flown)"/>

        <xsl:value-of select="$newline"/>
        <xsl:text>   "ceiling(document('')/*/</xsl:text>
        <xsl:text>months:name[@sequence='02'])" = </xsl:text>
        <xsl:value-of select="ceiling(document('')/*/months:name[@sequence='02'])"/>

        <xsl:value-of select="$newline"/>
        <xsl:value-of select="$newline"/>
        <xsl:for-each select="/report/month">
          <xsl:text>   </xsl:text>
          <xsl:value-of
            select="document('')/*/months:name[@sequence=current()/@sequence]"/>
          <xsl:text> - </xsl:text>
          <xsl:value-of select="format-number(miles-flown, '##,###')"/>
          <xsl:text> miles flown, </xsl:text>
          <xsl:value-of select="format-number(miles-earned, '##,###')"/>
          <xsl:text> miles earned.</xsl:text>
          <xsl:value-of select="$newline"/>
          <xsl:text>      (Averaged </xsl:text>
          <xsl:value-of select="ceiling(miles-earned div miles-flown)"/>
          <xsl:text> miles earned for each mile flown.)</xsl:text>
          <xsl:value-of select="$newline"/>
          <xsl:value-of select="$newline"/>
        </xsl:for-each>
      </xsl:template>

    </xsl:stylesheet>
When we transform the XML document with our stylesheet, here are the results:
    Tests of the ceiling() function:

       "ceiling('7.983')" = 8
       "ceiling('-7.893')" = -7
       "ceiling(/report/month[@sequence='01']/miles-flown)" = 12379
       "ceiling(document('')/*/months:name[@sequence='02'])" = NaN

       January - 12,379 miles flown, 35,215 miles earned.
          (Averaged 3 miles earned for each mile flown.)

       February - 32,857 miles flown, 92,731 miles earned.
          (Averaged 3 miles earned for each mile flown.)

       March - 19,920 miles flown, 76,725 miles earned.
          (Averaged 4 miles earned for each mile flown.)

       April - 18,903 miles flown, 31,781 miles earned.
          (Averaged 2 miles earned for each mile flown.)
Notice that when we invoked the ceiling() function against the string "February" (what document('')/*/months:name[@sequence='02'] resolves to), the function returned NaN. You can compare these results to those from the floor() function and the round() function.