Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development

  • Print
  • + Share This
This chapter is from the book

Rounding Numbers

There are three XPath functions for rounding numbers in your data source (Figure 4.13). You can round to the nearest integer (round), always round up (ceiling) (), or always round down (floor).

x m l
  file="artemis.jpg" w="528" h="349"/>

Figure 4.13. In this XML excerpt, you can see that the image’s size is 528 pixels wide by 349 pixels tall.

x s l t
  <xsl:attribute name="src">
    <xsl:value-of select=
  <xsl:attribute name="width">
    <xsl:value-of select=
      "ceiling(./@w div 2)"/>
  <xsl:attribute name="height">
    <xsl:value-of select=
      "ceiling(./@h div 2)"/>

Figure 4.14. I’d like the pictures to be shown at half their regular size. Since the width and height attributes only accept integers, I use the ceiling() function to round the division up to the nearest integer.

h t m l
 <p align="center">
  <img src="artemis.jpg"
    width="264" height="175"/>

Figure 4.15. After the XPath ceiling() function in, the width and height of the image are now half of their original values.

To round numbers:

  1. Type ceiling(, floor(, or round(, depending on whether you want to round up, down, or to the nearest integer.
  2. Then, type the expression which contains the number to be formatted.
  3. Finally, type ) to complete the function.
  • + Share This
  • 🔖 Save To Your Account