XML
  Home arrow XML arrow Page 2 - 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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
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 / 10
    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 - 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="/">
        <Html>
     <Head>
            <Title>News</Title>
          </Head>
         <Body>
           <CENTER><H1>Todays News</H1></CENTER><BR/>
      <xsl:apply-templates select="news/article"/>
         </Body>
       </Html>
      </xsl:template>

    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">

    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

    - 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
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway