# XML - Managing Data Exchange/C.5
## XML Style Sheet

Similar to the layout we visited in chapter 3, this style sheet lists each hotel in the XML document by country. But this time some new features have been added. Price range elements have been included, each hotel’s amenities are now listed, and the population of each country has been formatted to improve readability.

### XSLT Functions

When formatting XML output, there may be times when you might want to massage the data or get certain values for display. Placed within the XML style sheet, functions can be used to manipulate data during the transformation. We saw an example of this in chapter 3 when displaying the number of hotels within a city.
In order to make the population a little easier to read in our style sheet, we need to separate the digits into groups of threes and add commas. To do this we use the format-number( ) function. The purpose of this function is to convert a numeric value into a string using specified patterns that control the number of leading zeroes, separator between thousands, etc. The basic syntax of this function is as follows:
* number is the numeric value to be formatted
* pattern is a string that lays out the general representation of a number. Each character in the string represents either a digit from number or some special punctuation such as a comma or minus sign.
In order to display <population> with the digits grouped by three’s using commas as the separator, the format-number function was used in line {51} of our XML style sheet.
The following are the characters and their meanings used to represent the number format when using the format-number function within a style sheet:
| Symbol | Meaning |
| 0  #  .  ,  ;  -  %  X  ‘ | A digit. A digit, zero shows as absent. (period) Placeholder for decimal separator. Placeholder for grouping separator. Separate formats. Default prefix for negative. Multiply by 100 and show as a percentage. Any other characters can be used in the prefix or suffix. Used to quote special characters in a prefix or suffix. |
There are numerous other functions that you may find use for within a style sheet. The following are some additional numeric based functions that are useful when handling numbers within a stylesheet.
| Name | Description |
| ceiling | Returns the smallest integer that is not less than the number argument |
| floor | Returns the largest integer that is not greater than the number argument |
| number | Converts the value argument to a number |
| round | Rounds the number argument to the nearest integer |
| sum | Returns the total value of a set of numeric values in a node-set |
Figure 5-5 XML stylesheet – amenity.xsl
In the XML stylesheet, you will see two additional functions position and last. The position function returns the position of the current context node in the current context node-set. The last function returns the index number of the last node in the context. To list each amenity for each hotel, the transformation checks to see if the current position of the node is different than the position of the last context node in the set. If this returns true, then a comma is added as the amenities are listed.
Although this stylesheet builds upon the one we saw in chapter 3, notice the use of embedded tables to further specify the layout of the data being conveyed. Values and their indicators have been separated into table cells, allowing for a cleaner look and feel.