BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
XSLT
The XSLT Example: Creating listboxes and checkboxes using variables
The XSLT Example: Creating an HTML document with 'previous' and 'next' links
The XSLT Example: Generating a new stylesheet
The XSLT Example: Using different axes
The XSLT Example: Creating a summary of author sales for a publisher
The XSLT Example: Creating a summary of all Apollo flights
The XSLT Example:
The XSLT Element: xsl:with-param
The XSLT Element: xsl:when
The XSLT Element: xsl:variable
The XSLT Element: xsl:value-of
The XSLT Element: xsl:transform
The XSLT Element: xsl:text
The XSLT Element: xsl:template
The XSLT Element: xsl:stylesheet
The XSLT Element: xsl:strip-space
The XSLT Element: xsl:sort
The XSLT Element: xsl:processing-instruction
The XSLT Element: xsl:preserve-space
The XSLT Element: xsl:param
<< XQuery
.NET and XML >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :374

 
[XSLT Reference] [XPath Reference] [Download Reference Download this Reference]

Example: Numbering paragraphs and chapters

The xsl:number element is a very powerful and versatile tool for inserting chapter (paragraph, footnote, list item, ...) numbers automatically. It allows both for the specification of the format of a number (numerals, letters, roman numerals, Hebrew letter-numbers) as for the calculation of the appropriate value for the current node.
The value attribute can be used to specify the numeric value to send to the output. In this example, we don't use the value attribute. The numeric value is calculated using the level, count and from attributes.
The output format of the calculated value is specified by the attributes format, lang, letter-value, grouping-separator and grouping-size. Note how one xsl:number element can be used to create paragraph numbers such as III.a.
XSLT elements used:xsl:stylesheet xsl:template xsl:apply-templates xsl:number xsl:value-of
XML source:<?xml version="1.0"?> <book> <chapter title="It begins"> <para title="First paragraph"/> <para title="2nd paragraph"/> <para title="3rd paragraph"/> <para title="4th paragraph"/> </chapter> <chapter title="The sequel"> <para title="Paragraph"/> <para title="Yet another paragraph"/> </chapter> <chapter title="Final chapter"> <para title="Da paragraph"/> <para title="Last paragraph"/> </chapter> </book>
XSLT code:<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <formatted-book> <xsl:apply-templates select="book/chapter"/> </formatted-book> </xsl:template> <xsl:template match="chapter"> Chapter <xsl:number format="I"/>: <xsl:value-of select="@title"/> <xsl:apply-templates select="para"/> </xsl:template> <xsl:template match="para"> Paragraph <xsl:number level="multiple" count="para|chapter" format="I.a"/>: <xsl:value-of select="@title"/> (is paragraph nr. <xsl:number level="any" count="para" format="1"/>) </xsl:template> </xsl:stylesheet>
Resulting XML output:
saxon
xt
xalan
msxml3
msxml.NET
<?xml version="1.0" encoding="utf-8"?><formatted-book> Chapter I: It begins Paragraph I.a: First paragraph (is paragraph nr. 1) Paragraph I.b: 2nd paragraph (is paragraph nr. 2) Paragraph I.c: 3rd paragraph (is paragraph nr. 3) Paragraph I.d: 4th paragraph (is paragraph nr. 4) Chapter II: The sequel Paragraph II.a: Paragraph (is paragraph nr. 5) Paragraph II.b: Yet another paragraph (is paragraph nr. 6) Chapter III: Final chapter Paragraph III.a: Da paragraph (is paragraph nr. 7) Paragraph III.b: Last paragraph (is paragraph nr. 8) </formatted-book><?xml version="1.0" encoding="utf-8"?> <formatted-book> Chapter I: It begins Paragraph I.a: First paragraph (is paragraph nr. 1) Paragraph I.b: 2nd paragraph (is paragraph nr. 2) Paragraph I.c: 3rd paragraph (is paragraph nr. 3) Paragraph I.d: 4th paragraph (is paragraph nr. 4) Chapter II: The sequel Paragraph II.a: Paragraph (is paragraph nr. 5) Paragraph II.b: Yet another paragraph (is paragraph nr. 6) Chapter III: Final chapter Paragraph III.a: Da paragraph (is paragraph nr. 7) Paragraph III.b: Last paragraph (is paragraph nr. 8) </formatted-book><?xml version="1.0" encoding="UTF-8"?> <formatted-book> Chapter I: It begins Paragraph I.a: First paragraph (is paragraph nr. 1) Paragraph I.b: 2nd paragraph (is paragraph nr. 2) Paragraph I.c: 3rd paragraph (is paragraph nr. 3) Paragraph I.d: 4th paragraph (is paragraph nr. 4) Chapter II: The sequel Paragraph II.a: Paragraph (is paragraph nr. 5) Paragraph II.b: Yet another paragraph (is paragraph nr. 6) Chapter III: Final chapter Paragraph III.a: Da paragraph (is paragraph nr. 7) Paragraph III.b: Last paragraph (is paragraph nr. 8) </formatted-book><?xml version="1.0" encoding="UTF-16"?><formatted-book> Chapter I: It begins Paragraph I.a: First paragraph (is paragraph nr. 1) Paragraph I.b: 2nd paragraph (is paragraph nr. 2) Paragraph I.c: 3rd paragraph (is paragraph nr. 3) Paragraph I.d: 4th paragraph (is paragraph nr. 4) Chapter II: The sequel Paragraph II.a: Paragraph (is paragraph nr. 5) Paragraph II.b: Yet another paragraph (is paragraph nr. 6) Chapter III: Final chapter Paragraph III.a: Da paragraph (is paragraph nr. 7) Paragraph III.b: Last paragraph (is paragraph nr. 8) </formatted-book><?xml version="1.0" encoding="utf-8"?><formatted-book> Chapter I: It begins Paragraph I.a: First paragraph (is paragraph nr. 1) Paragraph I.b: 2nd paragraph (is paragraph nr. 2) Paragraph I.c: 3rd paragraph (is paragraph nr. 3) Paragraph I.d: 4th paragraph (is paragraph nr. 4) Chapter II: The sequel Paragraph II.a: Paragraph (is paragraph nr. 5) Paragraph II.b: Yet another paragraph (is paragraph nr. 6) Chapter III: Final chapter Paragraph III.a: Da paragraph (is paragraph nr. 7) Paragraph III.b: Last paragraph (is paragraph nr. 8) </formatted-book>

Note: You can now download the full content of the XPath reference, the XSLT reference and the DOM reference in one PDF document. This document contains the implementation tables, internal links to navigate through the references, a full linked table of contents. You can use free text search through the whole reference or print as a nicely formatted document. Download here...

© 2000 Teun Duynstee. Shown on TopXML.com. Information used from XSLT and XPath recommendations © W3C and MSDN documentation © Microsoft.
Do you have comments, additions or suggestions, mail me.

Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C
Immediate ASP.NET/C# Openings for C

View all Jobs (Add yours)
View all CV (Add yours)



bigfoot conferencing
swimming pool contractor
saveonconferences uk rates
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP