9.3 Roman Numerals

XSLT also supports numbering with Roman numerals in either upper- or lowercase with I, II, III, IV, or i, ii, iii, iv, and so forth. To get Roman numerals in your output, just supply an upper- or lowercase letter I or i in the format attribute.

The roman.xsl stylesheet, shown in Example 9-13, formats its output with lowercase Roman numerals.

Example 9-13. A stylesheet for numbering with Roman numerals
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/>      <xsl:template match="us">    <xsl:apply-templates select="state"/>  </xsl:template>      <xsl:template match="state">   <xsl:number format="i&#x9;"/>   <xsl:value-of select="."/>   <xsl:text>&#10;</xsl:text>  </xsl:template>     </xsl:stylesheet>

In this example, the lowercase letter i isn't preceded by any character, and it is followed by a single tab (&#x9;). Apply this stylesheet to us.xml with:

xalan us.xml roman.xsl

and you get the results shown in Example 9-14.

Example 9-14. U.S. states listed with Roman numerals
i       Alabama ii      Alaska iii     Arizona iv      Arkansas v       California vi      Colorado vii     Connecticut viii    Delaware ix      Florida x       Georgia xi      Hawaii xii     Idaho xiii    Illinois xiv     Indiana xv      Iowa xvi     Kansas xvii    Kentucky xviii   Louisiana xix     Maine xx      Maryland xxi     Massachusetts xxii    Minnesota xxiii   Michigan xxiv    Mississippi xxv     Missouri xxvi    Montana xxvii   Nebraska xxviii  Nevada xxix    New Hampshire xxx     New Jersey xxxi    New Mexico xxxii   New York xxxiii  North Carolina xxxiv   North Dakota xxxv    Oklahoma xxxvi   Oregon xxxvii  Ohio xxxviii Pennsylvania xxxix   Rhode Island xl      South Carolina xli     South Dakota xlii    Tennessee xliii   Texas xliv    Utah xlv     Vermont xlvi    Virginia xlvii   Washington xlviii  West Virginia xlix    Wisconsin l       Wyoming

9.3.1 Uppercase Roman Numerals

For uppercase Roman numerals, do the same thing as you do with alphabetical lists. The stylesheet upper-roman.xsl replaces the lowercase i with an uppercase I, followed by a decimal character reference for a tab (&#9;). (This stylesheet is not shown here but is in examples/ch09.) If you transform us.xml with upper-roman.xsl, it will give you uppercase Roman numerals rather than lowercase.



Learning XSLT
Learning XSLT
ISBN: 0596003277
EAN: 2147483647
Year: 2003
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net