Home arrow XML arrow Page 2 - An Introduction to XSLT

An Introduction to XSLT

XSLT allows you to create formatting structures which interpret and modify the existing XML elements. Learn about the syntax of XSLT elements, how the namespace attribute differs depending on the browser in use, and how to transform original XML elements.

Author Info:
By: Dan Wellman
Rating: 4 stars4 stars4 stars4 stars4 stars / 14
September 20, 2004
  1. · An Introduction to XSLT
  2. · Create Elements to Apply the Transformations
  3. · Another Template
  4. · Discussion of the Output
  5. · Page Masters
  6. · Block Level Elements

print this article

An Introduction to XSLT - Create Elements to Apply the Transformations
(Page 2 of 6 )

Now that we have the declarations out of the way, we can focus on creating the elements that apply the transformations. In order to transform the original XML elements, you need to create templates that match these elements and change them into other elements for display. The original elements that are matched are called patterns, so really you're creating templates that search for and match patterns.  The first pattern that we match in the source document is the root elements, in our case the <news> element. 

Add the following code to your XSLT file:

<xsl:template match="/">
       <CENTER><H1>Todays News</H1></CENTER><BR/>
  <xsl:apply-templates select="news/article"/>

What this block of code actually does is look for the root element of the source document, which is specified by the "/" in the first line of the template, and transforms the source element into a standard HTML document. We could just as easily have put the element name, in which case the first line of the template would read as:

<xsl:template match="news">
This does not work with Internet Explorer however, but would with other XML fluent browsers. Nevertheless, our HTML document is given the standard set of tags, with the addition of a nice large, centred heading. The template then specifies that additional templates should be matched to grand-children of the <news> element (or children of the <article> element), and added below the main heading. Now we need to create the templates that match the headline and story elements:

<xsl:template match="article">

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials