floor() Function |
Returns the largest integer that is not greater 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 floor() function returns NaN (not a number).
Output
The largest integer that is not greater than the argument, or NaN if the argument cannot be converted into a number.
Defined in
XPath section 4.4, Number Functions.
Example
The following stylesheet shows the results of invoking the floor() 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 floor() 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 floor() function:</xsl:text>

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

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

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

        <xsl:value-of select="$newline"/>
        <xsl:text>   "floor(document('')/*/months:name</xsl:text>
        <xsl:text>[@sequence='02'])" = </xsl:text>
        <xsl:value-of select="floor(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="floor(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>
Here is the output of our stylesheet:
    Tests of the floor() function:

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

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

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

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

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