Session IV Chapter 14 – Chapter 14 – XSLThttp://www.profburnett.com.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya 
SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
XSLT (eXtensible Stylesheet Language Transformation) 1.
XSL XSLT and XPath 11-Apr-17.
XML: Managing Data Exchange Stylesheets. Lesson Contents CSS The basic XSL file XSL transforms Templates Sort Numbering Parameters and Variables Datatypes.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XML Unit 6 October 31. XML, review XML is used to markup data Used to describe information Uses tags like HTML –But all tags are user-defined –Must be.
XSL Unit 6 November 2. XSL –eXtensible Stylesheet Language –Basically a stylesheet for XML documents XSL has three parts: –XSLT –XPath –XSL-FO.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
XSLT XSLT: eXtensible Stylesheet Language for Transformations - a language for transforming XML documents into any text- based format (e.g. HTML, plain.
ECA 228 Internet/Intranet Design I Intro to XSL. ECA 228 Internet/Intranet Design I XSL basics W3C standards for stylesheets – CSS – XSL: Extensible Markup.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.
1 cs XSL XSL is a standard that consists of three parts: XPath (navigation in documents) XPath was taught in the DB course, so it will not be.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XSLT transformations Or how to get your XML to become HMTL.
CIS 451: XSL Dr. Ralph Westfall February, Problems With XML no formatting capabilities contra formatting tags like, etc. in HTML CSS can be used.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
Session II Chapter 2 – Chapter 2 – XSLhttp://
Session IV Chapter 9 – XML Schemas
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
CIS 375—Web App Dev II XSL. 2 XSL Introduction XSL stands for _____________________________. XSL is the language used for manipulating and displaying.
Presentation Topic: XML and ASP Presented by Yanzhi Zhang.
Lecture 11 XSL Transformations (part 1: Introduction)
 2001 Prentice Hall, Inc. All rights reserved. Chapter 15 – Case Study: Message Forum with Active Server Pages Outline 15.1Introduction 15.2Setup and.
Session I Chapter 1 - Introduction to Web Development
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Applying eXtensible Style Sheets (XSL) Ellen Pearlman Eileen Mullin Programming.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
1 cs XSL XSL is a standard that consists of three parts: XPath (navigation in documents) XPath was taught in the DB course, so it will not be.
Session 1 Chapter 1 - Introduction to Web Development ITI 133: HTML5 Desktop and Mobile Level I
Dr. Chunbo Chu Week 3. XML Not a replacement for HTML. XML and HTML were designed with different goals: XML was designed to transport and store data,
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
Unit 3 — Advanced Internet Technologies Lesson 11 — Introduction to XSL.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
1 XMLXSL(T) and CSS NOEA/PQC (rev. fen) 2007 Stylesheets CSS:Cascading Style Sheets XSL(T):eXtended Stylesheet Language (Transformations)
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
XML Schema – XSLT Week 8 Web site:
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
1 Introducing Web Developer Tools Rapid application development tools ASP.NET-compatible web editors –Visual Studio.NET Professional Edition –Visual Studio.
XSLT: The XML transformation language
Session II Chapter 14 – XSLT
Unit 4 Representing Web Data: XML
Creating an XSLT Style Sheet for Formatting Data
Displaying XML Data with XSLT
Session IV Chapter 16 – XQuery
XSLT 1.0.
Database Processing with XML
ACG 4401 XSLT Extensible Stylesheet Language for Transformations
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Session II Chapter 2 - XSLT
Chapter 7 Representing Web Data: XML
HTML5 Level I Session I Chapter 1 - Introduction to Web Development
CS 431 – February 28, 2005 Carl Lagoze – Cornell University
XSL XSLT and XPath 24-Feb-19.
Unit 6 - XML Transformations
Presentation transcript:

Session IV Chapter 14 – Chapter 14 – XSLThttp://

Outline XSLT Introduction XSLT Browser Support Creating Simple Stylesheet XSLT Functions XSLT User Defined Functions Calling UDF XSLT Elements Generating Multiple Documents Validating XSLT Output Generating XHTML Output Generating XHTML Output on the Client Generating XHTML Output on the Server 8/1/2014Copyright © Carl M. Burnett2

XSLT Introduction XSL stands for EXtensible Stylesheet Language. CSS = Style Sheets for HTML XSL = Style Sheets for XML XSL - More Than a Style Sheet Language XSLT - a language for transforming XML documents XPath - a language for navigating in XML documents XSL-FO - a language for formatting XML documents XSLT = XSL Transformations 8/1/2014Copyright © Carl M. Burnett3 XQuery XPointerXLink XPath XSLT XSL-FO

XSLT Browser Support Internet Explorer supports XML, XSLT, and XPath from version 6. Chrome supports XML, XSLT, and XPath from version 1. Firefox supports XML, XSLT, and XPath from version 3. Safari supports XML and XSLT from version 3. Opera supports XML, XSLT, and XPath from version 9. 8/1/2014Copyright © Carl M. Burnett4

Creating Simple Stylesheet 8/1/2014Copyright © Carl M. Burnett5 Wonders of the World The famous Greek historian Herodotus wrote of seven great architectural achievements. And although his writings did not survive, he planted seeds for what has become the list of the Seven Wonders of the Ancient World. These ancient wonders are., and,

XSLT - Functions XQuery 1.0, XPath 2.0, and XSLT 2.0 share the same functions library. XSLT includes over 100 built-in functions. Functions Reference The default prefix for the function namespace is fn: The URI of the function namespace is: 8/1/2014Copyright © Carl M. Burnett6

XSLT - User Defined Functions (UDF) 8/1/2014Copyright © Carl M. Burnett7 You declare UDF’s name, input, what is does with the input, and its output. 1.Declare UDF Function - <xsl:function 2.Declare the function name - name=“UDF_Name“ 3.Declare any UDF Parameters – 4.Close out the UDF function –

Calling UDF 8/1/2014Copyright © Carl M. Burnett8 You call a UDF anywhere an XPath expression is expected. 1.Type – prefix: 2.Type – UDF _Name( 3.Type the value(s) of the input parameters separated by a comma.

XSLT - Elements 8/1/2014Copyright © Carl M. Burnett9 XSLT Element The element is used to build templates. The match attribute is used to associate a template with an XML element. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document). <xsl:stylesheet version="1.0" xmlns:xsl=" My CD Collection Title Artist.

XSLT - Elements 8/1/2014Copyright © Carl M. Burnett10 XSLT Element The element is used to extract the value of a selected node. <xsl:stylesheet version="1.0" xmlns:xsl=" My CD Collection Title Artist

XSLT - Elements 8/1/2014Copyright © Carl M. Burnett11 XSLT Element The element allows you to do looping in XSLT. <xsl:stylesheet version="1.0" xmlns:xsl=" My CD Collection Title Artist

XSLT - Elements 8/1/2014Copyright © Carl M. Burnett12 XSLT Element The element is used to sort the output. <xsl:stylesheet version="1.0" xmlns:xsl=" My CD Collection Title Artist

XSLT - Elements 8/1/2014Copyright © Carl M. Burnett13 XSLT Element The element is used to put a conditional test against the content of the XML file. <xsl:stylesheet version="1.0" xmlns:xsl=" My CD Collection Title Artist

XSLT - Elements 8/1/2014Copyright © Carl M. Burnett14 XSLT Element The element is used in conjunction with and to express multiple conditional tests. <xsl:stylesheet version="1.0" xmlns:xsl=" My CD Collection Title Artist

Generating Multiple Documents 8/1/2014Copyright © Carl M. Burnett15 With XSLT 2.0 you can generate multiple documents from a single process. 1. Type – <xsl:result-document to begin the output declaration. 2. Type – href=“output.uri’> where the URI identifies the location of document where the output for these XSLT instruction are located. 3. Type to close out the output instructions.

Validating XSLT Output 8/1/2014Copyright © Carl M. Burnett16 With XSLT 2.0 you can validate those output of a XSLT transformation against the XML schema. 1.Type – <xsl:import-schema 2. Type – schema-location=“schema.uri”/> where the URI identifies the location of XML Schema you want to use for validation. 3. Type in the root element of the output you want to validate: x sl:validation=:”strict”

Generating XHTML Output 8/1/2014Copyright © Carl M. Burnett17 Server-side XSL Transformations 1.Browser requests dynamic page 2.Web server finds page and passes it to application server 3.Application server scans page for instructions and gets XSLT fragment 4.Application server performs transformation (reads XSLT fragment, gets and formats xml data) 5.Application server inserts transformed fragment into page and passes it back to the web server 6.Web server sends finished page to browser PHP or ASP Code performs the XML to XHTML Transformation on the server.

Generating XHTML Output 8/1/2014Copyright © Carl M. Burnett18 Client-side XSL Transformations 1.Browser requests XML file 2.Server responds by sending XML file to browser 3.Browser reads XML directive and calls XSLT file 4.Server sends XSLT file to browser 5.Browser transforms XML data and displays it in browser

Generating XHTML Output - Linked File on Client 8/1/2014Copyright © Carl M. Burnett19 Colossus of Rhodes Κολοσσός της Ρόδου Rhodes, Greece earthquake In 294 BC, …………… XML File Wonders of the World Seven Wonders of the Ancient World The famous Greek historian Herodotus wrote of seven great architectural achievements. And although his writings did not survive, he planted seeds for what has become the list of the Seven Wonders of the Ancient World. XSL File – xsl Example XML File

Generating XHTML Output – JavaScript on Client 8/1/2014Copyright © Carl M. Burnett20 More versatile solution is to use a JavaScript to do the transformation. Using a JavaScript, we can: do browser-specific testing use different style sheets according to browser and user needs JavaScript Converts XML file to XHTML file in the client browser The loadXMLDoc() function does the following: Create an XMLHttpRequest object Use the open() and send() methods of the XMLHttpRequest object to send a request to a server Get the response data as XML data function loadXMLDoc(filename) { if (window.ActiveXObject) { xhttp = new ActiveXObject("Msxml2.XMLHTTP"); } else { xhttp = new XMLHttpRequest(); } xhttp.open("GET", filename, false); try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11 xhttp.send(""); return xhttp.responseXML; } function displayResult() { xml = loadXMLDoc("cdcatalog.xml"); xsl = loadXMLDoc("cdcatalog.xsl"); // code for IE if (window.ActiveXObject || xhttp.responseType == "msxml-document") { ex = xml.transformNode(xsl); document.getElementById("example").innerHTML = ex; } // code for Chrome, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); resultDocument = xsltProcessor.transformToFragment(xml, document); document.getElementById("example").appendChild(resultDocument); } } Example XML File

Generating XHTML Output – ASP/PHP on Server Transforming XML in the Browser will not work in a browser that doesn't have an XML parser. Transformation must be done on the server. Data is sent back to the browser as XHTML. PHP Code: Transform XML to XHTML on the Server ASP Code: Transform XML to XHTML on the Server 8/1/2014Copyright © Carl M. Burnett21 Example File

Student Exercise 2 1. Create an XSL Style Sheet (Slide 5) using XMLSpy 2. Create XML with XSL style sheet connected. (Slide 6) 3. Preview Transformed XML file in browser. 4. Link the XML file to your index webpage. 5. Post to live server. 6. Preview on live site. 8/1/2014Copyright © Carl M. Burnett22

Outline XSLT Introduction XSLT Browser Support Creating Simple Stylesheet XSLT Functions XSLT User Defined Functions Calling UDF XSLT Elements Generating Multiple Documents Validating XSLT Output Generating XHTML Output Generating XHTML Output on the Client Generating XHTML Output on the Server 8/1/2014Copyright © Carl M. Burnett23 Next: Chapter 5 - XSL-FO