XML
  Home arrow XML arrow An Introduction to XSLT
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

An Introduction to XSLT
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2004-09-20

    Table of Contents:
  • An Introduction to XSLT
  • Create Elements to Apply the Transformations
  • Another Template
  • Discussion of the Output
  • Page Masters
  • Block Level Elements

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    An Introduction to XSLT


    (Page 1 of 6 )

    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.


    Support files are available here for this article.


    XSL or eXtensible Stylesheet Language began life in much the same way as XML -- as a submission to the W3C. The W3C quickly released several working drafts before the final working draft was released in 2000. It shared some common design goals with XML, namely:

    • A quick design process
    • Transparency to users and developers
    • Ease of use
    • Avoidance of optional features
    • Suitable for use over the Internet

    As with XML, these goals were largely met. In October 2001, XSL was split into three separate working specifications by the W3C: XSLT, which is XSL Transformations, XSL-FO, which is XSL Formatting Objects, and Xpath, which defines parts of documents and linking structures. XSL-FO is now formally known as XSL. We will focus mainly on XSLT in the article, but XSL (XSL Formatting Objects) will be looked at briefly towards the end.
     
    Every well-formed XML document has a tree-like structure consisting of parent and child elements. What XSLT does is allow you to create formatting structures which interpret and modify the existing XML elements and can output the results of these structures to HTML (or other output media). It allows you to transform a source tree into a result tree of XML elements.

    Both XSLT and XSL must be well-formed documents, and as such XSLT documents must begin with the XML declaration. Following this comes the XSL:stylesheet element, which is the root element of the document and should contain at least the namespace declaration. 

    The transformation rules are then added as child elements of the root element. XSLT stylesheets are constructed using template rules that match one or nodes in the XML source documents logical tree. These template rules then create instances of fragments of the result tree.  The XSLT result tree is composed of the hierarchy of nodes in the XML document to which it is applied. 

    The syntax of all XSLT elements is the same:

    <xsl:tag-name attribute="value">
    </xsl:tag-name>

    These elements are reserved in the namespace URI that is set in the documents root element. Template rules also follow a similar syntax:

    <xsl:template attribute="value">
    </xsl:template>

    There are many template element attributes, some of which we'll explore during the course of this article. As an example of XSLT techniques, we will be creating a stylesheet document that transforms the XML document created in my previous XML article. 

    To start with then, as stated above, XSLT documents should be well-formed XML documents, so you start with the XML declaration:

    <?xml version="1.0"?>

    You then need to add the root element of the stylesheet document with the namespace declaration:

    <xsl:stylesheet xmlns:="http//www.w3.org/TR/WD-xsl">

    At this point it should be noted that the namespace attribute for XSLT documents differs depending on the browser in use. The namespace declaration used here is for IE5+ browsers. If IE5+ will not be used the following namespace declaration can be substituted:

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

    More XML Articles
    More By Dan Wellman


       · What is it with XML authors that can't use basic HTML correctly?Mixed case HTML...
       · excellent point, i know what you mean by this valid stuff...i see it from many...
       · Hi,Yes Dev ur right. It happens when u program it without going through its...
     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek