BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
XSLT
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
The XSLT Element: xsl:output
The XSLT Element: xsl:otherwise
The XSLT Element: xsl:number
The XSLT Element: xsl:namespace-alias
The XSLT Element: xsl:message
<< 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 :171

 
[XSLT Reference] [XPath Reference]

Example: Creating a summary of author sales for a publisher

XSLT elements used:xsl:stylesheet xsl:template xsl:text xsl:apply-templates xsl:key xsl:output xsl:sort xsl:copy xsl:value-of
XSLT and XPath functions used:key sum count position
XML source:<?xml version="1.0"?> <publisher> <books> <book> <title>Stranger in a strange land</title> <ISBN>0441788386</ISBN> <author-ref ref="rh"/> <sold>230000</sold> </book> <book> <title>Starman Jones</title> <ISBN>0345328116 </ISBN> <author-ref ref="rh"/> <author-ref ref="jldr"/> <sold>80000</sold> </book> </books> <authors> <author id="rh"> <first_name>Robert</first_name> <last_name>Heinlein</last_name> </author> <author id="jldr"> <first_name>Judy-Lyn</first_name> <last_name>Del Rey</last_name> </author> </authors> </publisher>
XSLT code:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key match="/publisher/books/book" use="author-ref/@ref" name="books-by-author"/> <xsl:output indent="yes" encoding="UTF-16"/> <xsl:template match="/"><bestsellers-list> <xsl:apply-templates select="/publisher/authors/author"> <xsl:sort data-type="number" order="descending" select="sum(key('books-by-author', @id)/sold)"/> </xsl:apply-templates> </bestsellers-list></xsl:template> <xsl:template match="author"> <xsl:copy> <name><xsl:value-of select="last_name"/>,<xsl:text> </xsl:text> <xsl:value-of select="first_name"/> </name> <total_publications> <xsl:value-of select="count(key('books-by-author', @id))"/> </total_publications> <total_sold> <xsl:value-of select="sum(key('books-by-author', @id)/sold)"/> </total_sold> <rank><xsl:value-of select="position()"/></rank> </xsl:copy> </xsl:template> </xsl:stylesheet>
Resulting XML output:
saxon
xt
xalan
msxml3
<?xml version="1.0" encoding="utf-8"?> <bestsellers-list> <author> <name>Heinlein, Robert</name> <total_publications>2</total_publications> <total_sold>310000</total_sold> <rank>1</rank> </author> <author> <name>Del Rey, Judy-Lyn</name> <total_publications>1</total_publications> <total_sold>80000</total_sold> <rank>2</rank> </author> </bestsellers-list>An error occurred<?xml version="1.0" encoding="UTF-16"?> <bestsellers-list> <author> <name>Heinlein, Robert</name> <total_publications>2</total_publications> <total_sold>310000</total_sold> <rank>1</rank> </author> <author> <name>Del Rey, Judy-Lyn</name> <total_publications>1</total_publications> <total_sold>80000</total_sold> <rank>2</rank> </author> </bestsellers-list> <?xml version="1.0" encoding="UTF-16"?> <bestsellers-list> <author> <name>Heinlein, Robert</name> <total_publications>2</total_publications> <total_sold>310000</total_sold> <rank>1</rank> </author> <author> <name>Del Rey, Judy-Lyn</name> <total_publications>1</total_publications> <total_sold>80000</total_sold> <rank>2</rank> </author> </bestsellers-list>

 

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)



efax
swimming pool contractor
reservationless conference calls
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