XML/XSLT stylesheet/number

Материал из Web эксперт
Версия от 11:26, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Add number list to the output

   <source lang="xml">

File: Data.xml <colors>

 <color>red</color>
 <color>green</color>
 <color>blue</color>
 <color>yellow</color>

</colors> File: Transform.xslt <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

 version="1.0">
 <xsl:output method="xml" omit-xml-declaration="yes" indent="no" />
 
 <xsl:template match="color">
   <xsl:number />
   .
   <xsl:apply-templates />
 </xsl:template>
 

</xsl:stylesheet> Output:

 1
   .
   red
 2
   .
   green
 3
   .
   blue
 4
   .
   yellow
</source>
   
  


format number by locale

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <?xml-stylesheet href="Transform.xslt" type="text/xsl"?> <format>

<number>100</number>
<number>1000</number>
<number>10000</number>
<number>100000</number>
<number>1000000</number>
<number>10000000</number>
<number>100000000</number>
<number>1000000000</number>

</format>

File: Transform.xslt <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" />
 <xsl:decimal-format name="de" decimal-separator=","
   grouping-separator="." />
 <xsl:decimal-format name="fr" decimal-separator=","
   grouping-separator=" " />
 <xsl:decimal-format name="ru" decimal-separator=","
   grouping-separator=" " />
 <xsl:decimal-format name="uk" decimal-separator="."
   grouping-separator="," />
 <xsl:decimal-format name="us" decimal-separator="."
   grouping-separator="," />
 <xsl:template match="format">
   <html>
     <head>
       <title>Number Formatter</title>
       <style type="text/css">
         table {margin-left:auto;margin-right:auto} td
         {text-align:right;padding: 5px 5px 5px 5px} h3
         {text-align:center}
       </style>
     </head>
     <body>

Number Formatter

<thead> </thead> <tbody> <xsl:apply-templates select="number" /> </tbody>
Deutschland France
               Россия
United Kingdom United States
     </body>
   </html>
 </xsl:template>
 <xsl:template match="number">
   <tr>
     <td>
       <xsl:value-of
         select="format-number(.,".###,00€","de")" />
     </td>
     <td>
       <xsl:value-of
         select="format-number(.," ###,00€","fr")" />
     </td>
     <td>
       <xsl:value-of
         select="format-number(.," ###,00p.","ru")" />
     </td>
     <td>
       <xsl:value-of
         select="format-number(.,"£,###.00","uk")" />
     </td>
     <td>
       <xsl:value-of
         select="format-number(.,"$,###.00","us")" />
     </td>
   </tr>
 </xsl:template>

</xsl:stylesheet> Output: <html>

  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <title>Number Formatter</title><style type="text/css">
         table {margin-left:auto;margin-right:auto} td
         {text-align:right;padding: 5px 5px 5px 5px} h3
         {text-align:center}
       </style></head>
  <body>

Number Formatter

<thead> </thead> <tbody> </tbody>
Deutschland France
                                 ??????
                               
United Kingdom United States
100,00?td> 100,00?td> 100,00p. ?0.00 $100.00
1.000,00?td> 1 000,00?td> 1 000,00p. ?000.00 $1,000.00
10.000,00?td> 10 000,00?td> 10 000,00p. ?,000.00 $10,000.00
100.000,00?td> 100 000,00?td> 100 000,00p. ?0,000.00 $100,000.00
1.000.000,00?td> 1 000 000,00?td> 1 000 000,00p. ?000,000.00 $1,000,000.00
10.000.000,00?td> 10 000 000,00?td> 10 000 000,00p. ?,000,000.00 $10,000,000.00
100.000.000,00?td> 100 000 000,00?td> 100 000 000,00p. ?0,000,000.00 $100,000,000.00
1.000.000.000,00?td> 1 000 000 000,00?td> 1 000 000 000,00p. ?000,000,000.00 $1,000,000,000.00
  </body>

</html>

</source>
   
  


Illustrates use of xsl:number element

   <source lang="xml">

File: Data.xml <?xml version="1.0" standalone="no" ?> <transcript>

 <student id="STU12345" name="name 1" status="active">
   <home_address>35 Wall Street, Wonderland, NJ</home_address>
   <interests>
     <interest>interest 1</interest>
     <interest>interest 2</interest>
     <interest>interest 3</interest>
   </interests>
 </student>
 <term>
   <heading name="Winter 1999" />
   <course>
     <course-name>course 1</course-name>
     <grade>A-</grade>
     <credits>4</credits>
   </course>
   <course>
     <course-name>course 2</course-name>
     <grade>B+</grade>
     <credits>3</credits>
   </course>
 </term>
 <summary>summary</summary>
 <comments>
    
   comments
 </comments>

</transcript> File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:template match="transcript">
   <HTML>
     <BODY>
       <xsl:apply-templates select="student" />

<xsl:apply-templates select="term/course"> <xsl:sort select="course-name" /> </xsl:apply-templates>
# Course Name Grade Credits
     </BODY>
   </HTML>
 </xsl:template>
 <xsl:template match="student">
   
     Student Transcript
   
   <P />
   
     
       Name:
       
         <xsl:value-of select="@name" />
       
       
ID: <xsl:value-of select="@id" />
<P /> </xsl:template> <xsl:template match="course"> <TR> <TD ALIGN="right"> <xsl:number value="position()" /> <xsl:text> of </xsl:text> <xsl:number value="last()" /> </TD> <TD> <xsl:value-of select="course-name" /> </TD> <TD> <xsl:value-of select="grade" /> </TD> <TD ALIGN="right"> <xsl:value-of select="credits" /> </TD> </TR> </xsl:template>

</xsl:stylesheet> Output: <HTML>

<BODY>Student Transcript

                   Name:
                   name 1
ID:
STU12345


# Course Name Grade Credits
1 of 2 course 1 A- 4
2 of 2 course 2 B+ 3
  </BODY>

</HTML>

</source>
   
  


number count="car" level="single" format="w"

   <source lang="xml">

File: Data.xml <?xml version="1.0" encoding="utf-8"?>

<cars>

 <manufacturer name="Chevrolet">
   <car>Cavalier</car>
   <car>Corvette</car>
   <car>Impala</car>
   <car>Malibu</car>
 </manufacturer>
 <manufacturer name="Ford">
   <car>Pinto</car>
   <car>Mustang</car>
   <car>Taurus</car>
 </manufacturer>
 <manufacturer name="Volkswagen">
   <car>Beetle</car>
   <car>Jetta</car>
   <car>Passat</car>
   <car>Touraeg</car>
 </manufacturer>

</cars> File: Transform.xslt

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="/">
   <xsl:text>Automobile manufacturers and their cars
</xsl:text>
   <xsl:for-each select="cars/manufacturer">
     <xsl:value-of select="@name"/>
     <xsl:text>
</xsl:text>
     <xsl:for-each select="car">
       <xsl:text>  Car </xsl:text>
       <xsl:number count="car" level="single" format="w"/>
       <xsl:text>: </xsl:text>
       <xsl:value-of select="."/>
       <xsl:text>
</xsl:text>
     </xsl:for-each>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet> Output: Automobile manufacturers and their cars Chevrolet

 Car one: Cavalier
 Car two: Corvette
 Car three: Impala
 Car four: Malibu

Ford

 Car one: Pinto
 Car two: Mustang
 Car three: Taurus

Volkswagen

 Car one: Beetle
 Car two: Jetta
 Car three: Passat
 Car four: Touraeg
</source>
   
  


number count="manufacturer|car" level="multiple" format="1.1. "

   <source lang="xml">

File: Data.xml <?xml version="1.0" encoding="utf-8"?> <cars>

 <manufacturer name="Chevrolet">
   <car>Cavalier</car>
   <car>Corvette</car>
   <car>Impala</car>
   <car>Malibu</car>
 </manufacturer>
 <manufacturer name="Ford">
   <car>Pinto</car>
   <car>Mustang</car>
   <car>Taurus</car>
 </manufacturer>
 <manufacturer name="Volkswagen">
   <car>Beetle</car>
   <car>Jetta</car>
   <car>Passat</car>
   <car>Touraeg</car>
 </manufacturer>

</cars> File: Transform.xslt <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="/">
   <xsl:text>Automobile manufacturers and their cars
</xsl:text>
   <xsl:for-each select="cars/manufacturer">
     <xsl:value-of select="@name"/>
     <xsl:text>
</xsl:text>
     <xsl:for-each select="car">
       <xsl:sort select="."/>
       <xsl:text>  </xsl:text>
       <xsl:if test="(position() mod 2) = 0">
         <xsl:number count="manufacturer|car" level="multiple" format="1.1. "/>
       </xsl:if>
       <xsl:value-of select="."/>
       <xsl:text>
</xsl:text>
     </xsl:for-each>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet> Output: Automobile manufacturers and their cars Chevrolet

 Cavalier
 1.2. Corvette
 Impala
 1.4. Malibu

Ford

 Mustang
 2.1. Pinto
 Taurus

Volkswagen

 Beetle
 3.2. Jetta
 Passat
 3.4. Touraeg
</source>
   
  


number count="manufacturer" level="multiple" format="1."

   <source lang="xml">

File: Data.xml <?xml version="1.0" encoding="utf-8"?> <cars>

 <manufacturer name="Chevrolet">
   <car>Cavalier</car>
   <car>Corvette</car>
   <car>Impala</car>
   <car>Malibu</car>
 </manufacturer>
 <manufacturer name="Ford">
   <car>Pinto</car>
   <car>Mustang</car>
   <car>Taurus</car>
 </manufacturer>
 <manufacturer name="Volkswagen">
   <car>Beetle</car>
   <car>Jetta</car>
   <car>Passat</car>
   <car>Touraeg</car>
 </manufacturer>

</cars>

File: Transform.xslt <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="/">
   <xsl:text>Automobile manufacturers and their cars
</xsl:text>
   <xsl:for-each select="cars/manufacturer">
     <xsl:value-of select="@name"/>
     <xsl:text>
</xsl:text>
     <xsl:for-each select="car">
       <xsl:sort select="."/>
       <xsl:text>  </xsl:text>
       <xsl:if test="(position() mod 2) = 0">
         <xsl:number count="manufacturer" level="multiple" format="1."/>
         <xsl:value-of select="position()"/>
         <xsl:text>. </xsl:text>
       </xsl:if>
       <xsl:value-of select="."/>
       <xsl:text>
</xsl:text>
     </xsl:for-each>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet> Output: Automobile manufacturers and their cars Chevrolet

 Cavalier
 1.2. Corvette
 Impala
 1.4. Malibu

Ford

 Mustang
 2.2. Pinto
 Taurus

Volkswagen

 Beetle
 3.2. Jetta
 Passat
 3.4. Touraeg
</source>
   
  


number count="name" format=" 1. "

   <source lang="xml">

File: Data.xml <?xml version="1.0" encoding="UTF-8"?> <provinces>

<name>Alberta</name>
<name>British Columbia</name>
<name>Manitoba</name>
<name>New Brunswick</name>
<name>Newfoundland and Labrador</name>
<name>Northwest Territories</name>
<name>Nova Scotia</name>
<name>Nunavut</name>
<name>Ontario</name>
<name>Prince Edward Island</name>
<name>Quebec</name>
<name>Saskatchewan</name>
<name>Yukon</name>

</provinces> File: Transform.xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text" />
 <xsl:template match="provinces">
   <xsl:apply-templates select="name" />
 </xsl:template>
 <xsl:template match="name">
   <xsl:number count="name" format=" 1. " />
   <xsl:value-of select="." />
   <xsl:text>
</xsl:text>
 </xsl:template>

</xsl:stylesheet>

1. Alberta
2. British Columbia
3. Manitoba
4. New Brunswick
5. Newfoundland and Labrador
6. Northwest Territories
7. Nova Scotia
8. Nunavut
9. Ontario
10. Prince Edward Island
11. Quebec
12. Saskatchewan
13. Yukon
</source>
   
  


number format=" 1. "

   <source lang="xml">

File: Data.xml <?xml version="1.0" encoding="UTF-8"?> <provinces>

<name>Alberta</name>
<name>British Columbia</name>
<name>Manitoba</name>
<name>New Brunswick</name>
<name>Newfoundland and Labrador</name>
<name>Northwest Territories</name>
<name>Nova Scotia</name>
<name>Nunavut</name>
<name>Ontario</name>
<name>Prince Edward Island</name>
<name>Quebec</name>
<name>Saskatchewan</name>
<name>Yukon</name>

</provinces>

File: Transform.xslt <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text" />
 <xsl:template match="provinces">
   <xsl:apply-templates select="name" />
 </xsl:template>
 <xsl:template match="name">
   <xsl:number format=" 1. " />
   <xsl:value-of select="." />
   <xsl:text>
</xsl:text>
 </xsl:template>

</xsl:stylesheet> Output:

1. Alberta
2. British Columbia
3. Manitoba
4. New Brunswick
5. Newfoundland and Labrador
6. Northwest Territories
7. Nova Scotia
8. Nunavut
9. Ontario
10. Prince Edward Island
11. Quebec
12. Saskatchewan
13. Yukon
</source>
   
  


number format=" " grouping-size="3" grouping-separator=","

   <source lang="xml">

File: Data.xml <generator>

<num/>
<num/>
<num/>

</generator>

File: Transform.xslt <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text" />
 <xsl:template match="generator">
   <xsl:apply-templates select="num" />
 </xsl:template>
 <xsl:template match="num">
   <xsl:number format="
" grouping-size="3"
     grouping-separator="," />
 </xsl:template>

</xsl:stylesheet> Output:

1 2 3

</source>
   
  


number from="section" level="multiple" count="section | item" format=" a "

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <outline>

<section title="US coin denominations">
 <item>cent</item>
 <item>nickel</item>
 <item>dime</item>
 <item>quarter</item>
 <item>half dollar</item>
 <item>dollar</item>
</section>

</outline>

File: Transform.xslt <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text" />
 <xsl:template match="outline">
   <xsl:for-each select="section|//item">
     <xsl:number from="section" level="multiple"
       count="section | item" format=" a " />
     <xsl:value-of select="@title | text()" />
     <xsl:text>
</xsl:text>
   </xsl:for-each>
   <xsl:text>
 </xsl:text>
 </xsl:template>

</xsl:stylesheet> Output:

a US coin denominations
a cent
b nickel
c dime
d quarter
e half dollar
f dollar

</source>
   
  


number level="any" count="chapter|sect1|sect2|sect3" format="1. "

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <book>

 <title>XSLT Topics</title>
 <chapter>
   <title>XPath</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Stylesheet Basics</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Branching and Control Elements</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Functions</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Creating Links and Cross-References</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Sorting and Grouping Elements</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Combining XML Documents</title>
   <para>text</para>
 </chapter>

</book> File: Transform.xslt <?xml version="1.0"?>

<xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="book">
   <xsl:for-each select="chapter|.//sect1|.//sect2|.//sect3">
     <xsl:number level="any" count="chapter|sect1|sect2|sect3" format="1. "/>
       <xsl:value-of select="title"/>
       <xsl:text>
</xsl:text>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet> Output: 1. XPath 2. Stylesheet Basics 3. Branching and Control Elements 4. Functions 5. Creating Links and Cross-References 6. Sorting and Grouping Elements 7. Combining XML Documents

</source>
   
  


number level="any" from="book" count="chapter" format="1."

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <book>

 <title>XSLT Topics</title>
 <chapter>
   <title>title 1</title>
 </chapter>
 <chapter>
   <title>title 2</title>
 </chapter>
 <chapter>
   <title>title 3</title>
 </chapter>
 <chapter>
   <title>title 4</title>
 </chapter>
 <chapter>
   <title>title 5</title>
 </chapter>
 <chapter>
   <title>title 6</title>
 </chapter>
 <chapter>
   <title>title 7</title>
 </chapter>

</book>

File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="book">
   <xsl:for-each select=".//sect3">
     <xsl:number level="any" from="book" count="chapter" format="1."/>
     <xsl:number level="any" from="chapter" count="sect1" format="1."/>
     <xsl:number level="any" from="sect1" count="sect2" format="1."/>
     <xsl:number level="any" from="sect2" count="sect3" format="1. "/>
     <xsl:value-of select="title"/>
     <xsl:text>
</xsl:text>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet>

</source>
   
  


number level="multiple" count="chapter|sect1|sect2" format="I-A-i: "

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <book>

 <title>XSLT Topics</title>
 <chapter>
   <title>title 1</title>
 </chapter>
 <chapter>
   <title>title 2</title>
 </chapter>
 <chapter>
   <title>title 3</title>
 </chapter>
 <chapter>
   <title>title 4</title>
 </chapter>
 <chapter>
   <title>title 5</title>
 </chapter>
 <chapter>
   <title>title 6</title>
 </chapter>
 <chapter>
   <title>title 7</title>
 </chapter>

</book>

File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="book">
   <xsl:for-each select=".">
     <xsl:number level="multiple" count="chapter|sect1|sect2" format="I-A-i: "/>
       <xsl:value-of select="title"/>
       <xsl:text>
</xsl:text>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet>

</source>
   
  


number level="multiple" count="chapter|sect1|sect2|sect3" format="1.1.1.1. "

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <book>

 <title>XSLT Topics</title>
 <chapter>
   <title>XPath</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Stylesheet Basics</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Branching and Control Elements</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Functions</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Creating Links and Cross-References</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Sorting and Grouping Elements</title>
   <para>text</para>
 </chapter>
 <chapter>
   <title>Combining XML Documents</title>
   <para>text</para>
 </chapter>

</book>

File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="book">
   <xsl:for-each select="chapter|.//sect1|.//sect2|.//sect3">
     <xsl:number level="multiple" count="chapter|sect1|sect2|sect3" format="1.1.1.1. "/>
       <xsl:value-of select="title"/>
       <xsl:text>
</xsl:text>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet> Output: 1. XPath 2. Stylesheet Basics 3. Branching and Control Elements 4. Functions 5. Creating Links and Cross-References 6. Sorting and Grouping Elements 7. Combining XML Documents

</source>
   
  


number level="multiple" count="*" from="data" format="1.1.1 "

   <source lang="xml">

File: Data.xml <?xml version="1.0" encoding="US-ASCII"?>

 <record>
   <name>
     <full>A</full>
     <brief>I</brief>
   </name>
   <address>
     <street>uite 330</street>
     <city>Regina</city>
     <state>SK</state>
     90292
     <nation>USA</nation>
   </address>
   <tel>
     <phone>+1 310 823 9358</phone>
     <fax>+1 310 823 8649</fax>
     <email>i@i.org</email>
   </tel>
 </record>

File: Transform.xslt <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text" />
 <xsl:strip-space elements="*" />
 <xsl:template match="/">
   <xsl:apply-templates select="data//*" />
 </xsl:template>
 <xsl:template match="data//*">
   <xsl:number level="multiple" count="*" from="data"
     format="1.1.1 " />
   <xsl:value-of select="name()" />
   <xsl:text>: </xsl:text>
   <xsl:text>	</xsl:text>
   <xsl:value-of select="text()" />
   <xsl:text>
</xsl:text>
 </xsl:template>

</xsl:stylesheet> Output: 1 record: 1.1 name: 1.1.1 full: A 1.1.2 brief: I 1.2 address: 1.2.1 street: uite 330 1.2.2 city: Regina 1.2.3 state: SK 1.2.4 code: 90292 1.2.5 nation: USA 1.3 tel: 1.3.1 phone: +1 310 823 9358 1.3.2 fax: +1 310 823 8649 1.3.3 email: i@i.org

</source>
   
  


number level="multiple" count="section | item" format="i. a. "

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <outline>

<section title="US coin denominations">
 <item>cent</item>
 <item>nickel</item>
 <item>dime</item>
 <item>quarter</item>
 <item>half dollar</item>
 <item>dollar</item>
</section>

</outline>

File: Transform.xslt <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text" />
 <xsl:template match="outline">
   <xsl:for-each select="section|//item">
     <xsl:number level="multiple" count="section | item"
       format="i. a. " />
     <xsl:value-of select="@title | text()" />
     <xsl:text>
</xsl:text>
   </xsl:for-each>
   <xsl:text>
 </xsl:text>
 </xsl:template>

</xsl:stylesheet> Output: i. US coin denominations i. a. cent i. b. nickel i. c. dime i. d. quarter i. e. half dollar i. f. dollar

</source>
   
  


number level="single" count="chapter|sect1|sect2|sect3" format="1.1.1.1. "

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <book>

 <title>XSLT Topics</title>
 <chapter>
   <title>title 1</title>
 </chapter>
 <chapter>
   <title>title 2</title>
 </chapter>
 <chapter>
   <title>title 3</title>
 </chapter>
 <chapter>
   <title>title 4</title>
 </chapter>
 <chapter>
   <title>title 5</title>
 </chapter>
 <chapter>
   <title>title 6</title>
 </chapter>
 <chapter>
   <title>title 7</title>
 </chapter>

</book>

File: Transform.xslt

<?xml version="1.0"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="book">
   <xsl:for-each select="chapter|.//sect1|.//sect2|.//sect3">
     <xsl:number level="single" count="chapter|sect1|sect2|sect3" format="1.1.1.1. "/>
       <xsl:value-of select="title"/>
       <xsl:text>
</xsl:text>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet> Output: 1. title 1 2. title 2 3. title 3 4. title 4 5. title 5 6. title 6 7. title 7

</source>
   
  


number value="1000000" grouping-size="3" grouping-separator="."

   <source lang="xml">

File: Data.xml <thanks>Thanks</thanks>

File: Transform.xslt <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text" />
 <xsl:template match="thanks">
   <xsl:value-of select="." />
   <xsl:number value="1000000" grouping-size="3"
     grouping-separator="." />
   <xsl:text>!</xsl:text>
 </xsl:template>

</xsl:stylesheet> Output: Thanks1.000.000!

</source>
   
  


Output number and count

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <shopping-list>

  <item>bananas</item>
  <item>apples</item>
  <special-item>item special</special-item>
  <item>grapes</item>
  <special-item>item 2</special-item>
  <item>cherries</item>

</shopping-list> File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="item | special-item">
   <xsl:number count="item | special-item" />
   <xsl:text> </xsl:text>
   <xsl:value-of select="." />
   
</xsl:template>

</xsl:stylesheet> Output: <?xml version="1.0" encoding="UTF-8"?>

  1 bananas
2 apples
3 item special
4 grapes
5 item 2
6 cherries
</source>


Output Number from any level

   <source lang="xml">

File: Data.xml <poem>

  <author>author 1</author>
  <date>1912</date>
  <title>Song</title>
 <stanza>
     <line>line 1</line>
     <line>line 2</line>
     <line>line 3</line>
     <line>line 4</line>
  </stanza>
  <stanza>
     <line>line 5</line>
     <line>line 6</line>
     <line>line 7</line>
     <line>line 8</line>
  </stanza>
  <stanza>
     <line>line 9</line>
     <line>line 10</line>
     <line>line 11</line>
     <line>line 12</line>
  </stanza>

</poem> File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
   <html>
     <body>

<xsl:apply-templates select="/poem/stanza" />

     </body>
   </html>
 </xsl:template>
 <xsl:template match="stanza">

<xsl:apply-templates />

 </xsl:template>
 <xsl:template match="line">
   <tr>
     <td width="350">
       <xsl:value-of select="." />
     </td>
     <td width="50">
       <xsl:variable name="line-nr">
         <xsl:number level="any" from="poem" />
       </xsl:variable>
       <xsl:if test="$line-nr mod 3 = 0">
         <xsl:value-of select="$line-nr" />
       </xsl:if>
     </td>
   </tr>
 </xsl:template>

</xsl:stylesheet> Output: <html>

  <body>

<p>

line 1
line 2
line 3 3
line 4

line 5
line 6 6
line 7
line 8

line 9 9
line 10
line 11
line 12 12

     </p>
  </body>

</html>

</source>