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

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

Example: Using different axes

XSLT elements used:xsl:stylesheet xsl:template xsl:apply-templates xsl:call-template xsl:value-of
XSLT and XPath functions used:count
XML source:<?xml version="1.0"?> <book> <chapter title="The sequel" xmlns:annotation="http://some.annotation.com/namespace/"> <annotation:para title="Paragraph"/> <para title="Yet another paragraph" annotation:referral="Tom Sawyer"/> <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="/"> <Overview>Overview of numbers of nodes on all axes <xsl:apply-templates select="@*|node()"/> </Overview> </xsl:template> <xsl:template match="@*|node()"> <xsl:call-template name="axes-summary"/> <xsl:apply-templates select="@*|node()"/> </xsl:template> <xsl:template name="axes-summary"> name(): <xsl:value-of select="name()"/> local-name(): <xsl:value-of select="local-name()"/> namespace-uri(): <xsl:value-of select="namespace-uri()"/> Axis self: <xsl:value-of select="count(self::*)"/> Axis child: <xsl:value-of select="count(child::*)"/> Axis descendant: <xsl:value-of select="count(descendant::*)"/> Axis ancestor: <xsl:value-of select="count(ancestor::*)"/> Axis preceding-sibling: <xsl:value-of select="count(preceding-sibling::*)"/> Axis following-sibling: <xsl:value-of select="count(following-sibling::*)"/> Axis attribute: <xsl:value-of select="count(attribute::*)"/> Axis preceding: <xsl:value-of select="count(preceding::*)"/> Axis following: <xsl:value-of select="count(following::*)"/> Axis namespace: <xsl:value-of select="count(namespace::*)"/> </xsl:template> </xsl:stylesheet>
Resulting XML output:
saxon
xt
xalan
msxml3
msxml.NET
<?xml version="1.0" encoding="utf-8"?><Overview>Overview of numbers of nodes on all axes name(): book local-name(): book namespace-uri(): Axis self: 1 Axis child: 1 Axis descendant: 4 Axis ancestor: 0 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 0 Axis namespace: 1 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 1 Axis preceding-sibling: 0 Axis following-sibling: 1 Axis attribute: 0 Axis preceding: 0 Axis following: 4 Axis namespace: 0 name(): chapter local-name(): chapter namespace-uri(): Axis self: 1 Axis child: 3 Axis descendant: 3 Axis ancestor: 1 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 1 Axis preceding: 0 Axis following: 0 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 3 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 3 Axis attribute: 0 Axis preceding: 0 Axis following: 3 Axis namespace: 0 name(): annotation:para local-name(): para namespace-uri(): http://some.annotation.com/namespace/ Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 2 Axis attribute: 1 Axis preceding: 0 Axis following: 2 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 2 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 1 Axis following-sibling: 2 Axis attribute: 0 Axis preceding: 1 Axis following: 2 Axis namespace: 0 name(): para local-name(): para namespace-uri(): Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 1 Axis following-sibling: 1 Axis attribute: 2 Axis preceding: 1 Axis following: 1 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 1 Axis following: 1 Axis namespace: 0 name(): annotation:referral local-name(): referral namespace-uri(): http://some.annotation.com/namespace/ Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 1 Axis following: 1 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 2 Axis following-sibling: 1 Axis attribute: 0 Axis preceding: 2 Axis following: 1 Axis namespace: 0 name(): para local-name(): para namespace-uri(): Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 2 Axis following-sibling: 0 Axis attribute: 1 Axis preceding: 2 Axis following: 0 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 2 Axis following: 0 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 3 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 3 Axis following: 0 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 1 Axis preceding-sibling: 1 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 4 Axis following: 0 Axis namespace: 0</Overview>An error occurred<?xml version="1.0" encoding="UTF-8"?> <Overview>Overview of numbers of nodes on all axes name(): book local-name(): book namespace-uri(): Axis self: 1 Axis child: 1 Axis descendant: 4 Axis ancestor: 0 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 0 Axis namespace: 1 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 1 Axis preceding-sibling: 0 Axis following-sibling: 1 Axis attribute: 0 Axis preceding: 0 Axis following: 4 Axis namespace: 0 name(): chapter local-name(): chapter namespace-uri(): Axis self: 1 Axis child: 3 Axis descendant: 3 Axis ancestor: 1 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 1 Axis preceding: 0 Axis following: 0 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 3 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 3 Axis attribute: 0 Axis preceding: 0 Axis following: 3 Axis namespace: 0 name(): annotation:para local-name(): para namespace-uri(): http://some.annotation.com/namespace/ Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 2 Axis attribute: 1 Axis preceding: 0 Axis following: 2 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 2 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 1 Axis following-sibling: 2 Axis attribute: 0 Axis preceding: 1 Axis following: 2 Axis namespace: 0 name(): para local-name(): para namespace-uri(): Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 1 Axis following-sibling: 1 Axis attribute: 2 Axis preceding: 1 Axis following: 1 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 1 Axis following: 1 Axis namespace: 0 name(): annotation:referral local-name(): referral namespace-uri(): http://some.annotation.com/namespace/ Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 1 Axis following: 1 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 2 Axis following-sibling: 1 Axis attribute: 0 Axis preceding: 2 Axis following: 1 Axis namespace: 0 name(): para local-name(): para namespace-uri(): Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 2 Axis following-sibling: 0 Axis attribute: 1 Axis preceding: 2 Axis following: 0 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 2 Axis following: 0 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 3 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 3 Axis following: 0 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 1 Axis preceding-sibling: 1 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 4 Axis following: 0 Axis namespace: 0</Overview><?xml version="1.0" encoding="UTF-16"?><Overview>Overview of numbers of nodes on all axes name(): book local-name(): book namespace-uri(): Axis self: 1 Axis child: 1 Axis descendant: 4 Axis ancestor: 0 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 0 Axis namespace: 1 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 1 Axis preceding-sibling: 0 Axis following-sibling: 1 Axis attribute: 0 Axis preceding: 0 Axis following: 4 Axis namespace: 0 name(): chapter local-name(): chapter namespace-uri(): Axis self: 1 Axis child: 3 Axis descendant: 3 Axis ancestor: 1 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 1 Axis preceding: 0 Axis following: 0 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 0 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 3 Axis attribute: 0 Axis preceding: 0 Axis following: 3 Axis namespace: 0 name(): annotation:para local-name(): para namespace-uri(): http://some.annotation.com/namespace/ Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 2 Axis attribute: 1 Axis preceding: 0 Axis following: 2 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 2 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 1 Axis following-sibling: 2 Axis attribute: 0 Axis preceding: 1 Axis following: 2 Axis namespace: 0 name(): para local-name(): para namespace-uri(): Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 1 Axis following-sibling: 1 Axis attribute: 2 Axis preceding: 1 Axis following: 1 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 1 Axis following: 1 Axis namespace: 0 name(): annotation:referral local-name(): referral namespace-uri(): http://some.annotation.com/namespace/ Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 1 Axis following: 1 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 2 Axis following-sibling: 1 Axis attribute: 0 Axis preceding: 2 Axis following: 1 Axis namespace: 0 name(): para local-name(): para namespace-uri(): Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 2 Axis following-sibling: 0 Axis attribute: 1 Axis preceding: 2 Axis following: 0 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 2 Axis following: 0 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 3 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 3 Axis following: 0 Axis namespace: 0 name(): local-name(): namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 1 Axis preceding-sibling: 1 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 4 Axis following: 0 Axis namespace: 0</Overview><?xml version="1.0" encoding="utf-8"?><Overview>Overview of numbers of nodes on all axes name(): book local-name(): book namespace-uri(): Axis self: 1 Axis child: 1 Axis descendant: 4 Axis ancestor: 0 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 0 Axis namespace: 1 name(): chapter local-name(): chapter namespace-uri(): Axis self: 1 Axis child: 3 Axis descendant: 3 Axis ancestor: 1 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 1 Axis preceding: 0 Axis following: 0 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 3 Axis namespace: 0 name(): annotation:para local-name(): para namespace-uri(): http://some.annotation.com/namespace/ Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 0 Axis following-sibling: 2 Axis attribute: 1 Axis preceding: 0 Axis following: 2 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 0 Axis following: 2 Axis namespace: 0 name(): para local-name(): para namespace-uri(): Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 1 Axis following-sibling: 1 Axis attribute: 2 Axis preceding: 1 Axis following: 1 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 1 Axis following: 1 Axis namespace: 0 name(): annotation:referral local-name(): referral namespace-uri(): http://some.annotation.com/namespace/ Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 1 Axis following: 1 Axis namespace: 0 name(): para local-name(): para namespace-uri(): Axis self: 1 Axis child: 0 Axis descendant: 0 Axis ancestor: 2 Axis preceding-sibling: 2 Axis following-sibling: 0 Axis attribute: 1 Axis preceding: 2 Axis following: 0 Axis namespace: 2 name(): title local-name(): title namespace-uri(): Axis self: 0 Axis child: 0 Axis descendant: 0 Axis ancestor: 3 Axis preceding-sibling: 0 Axis following-sibling: 0 Axis attribute: 0 Axis preceding: 2 Axis following: 0 Axis namespace: 0</Overview>

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)



help desk support
swimming pool contractor
conference call
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