XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN 0-619-10187- 3.

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

XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
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.
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.
XML: Extensible Markup Language
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSL XSLT and XPath 11-Apr-17.
Transforming XML Part I Document Navigation with XPath John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)
Lecture 10. Back to the table example We can now return to considering in detail the first XSLT style-sheet we saw –The one which, when applied to the.
Tutorial 16 Working with Dynamic Content and Styles.
Rendering XML documents with XSL The most powerful approaches to rendering XML documents involve using XSL (eXtensible Stylesheet Language) XSL enables.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
XSL Unit 6 November 2. XSL –eXtensible Stylesheet Language –Basically a stylesheet for XML documents XSL has three parts: –XSLT –XPath –XSL-FO.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET (Using XSLT style sheet to calculate values based.
Tutorial 11 Creating XML Document
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)
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
SD2520 Databases using XML and JQuery
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.
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
CSE3201/CSE4500 Information Retrieval Systems
XSL XML Stylesheet Langauage. XPath Notation for addressing elements in an XML document /xyz - selects the root element /xyz/abc - selects all elements.
XSLT and XPath, by Dr. Khalil1 XSL, XSLT and XPath Dr. Awad Khalil Computer Science Department AUC.
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.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
XML About XML Things to be known Related Technologies XML DOC Structure Exploring XML.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
Extensible Stylesheet Language Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University XSL-FO XSLT.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Lecture 11 XSL Transformations (part 1: Introduction)
XP 1 TUTORIAL 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 – XSL: Extensible Stylesheet Language Transformations (XSLT) Outline 12.1Introduction 12.2Setup.
XP 1 Creating an XML Document Developing an XML Document for the Jazz Warehouse XML Tutorial.
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.
XML Design Goals 1.XML must be easily usable over the Internet 2.XML must support a wide variety of applications 3.XML must be compatible with SGML 4.It.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
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.
XPath. XPath, the XML Path Language, is a query language for selecting nodes from an XML document. The XPath language is based on a tree representation.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
XP 1 XSLT II Robin Burke ECT 360. XP 2 Outline Conditionals Numbering Functions and operators Variables and parameters Named and recursive templates.
XP 1 XSLT II Robin Burke ECT 360. XP 2 Homework #4 Forgot we hadn't covered "choose" becomes extra credit My books.xml didn't include descriptions.
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
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.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
CH 15 XSL Transformations 1. Objective What is XSL? Overview of XSL transformations Understanding XSL templates Computing the value of a node with xsl:value-of.
XML: Extensible Markup Language
Unit 4 Representing Web Data: XML
XSLT 1.0.
Chapter 7 Representing Web Data: XML
New Perspectives on XML
Presentation transcript:

XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN

XP New Perspectives on XML Tutorial 6 2 OBJECTIVES In this chapter, you will: Learn about the history and theory of XSL Create an XSLT style sheet Be introduced to syntax of the XPath language Transform an XML document into an HTML file Create templates to format sections of the XML document

XP New Perspectives on XML Tutorial 6 3 OBJECTIVES In this chapter, you will: Sort the contents of an XML document Create conditional nodes to generate different HTML code Use predicates to select subsets of an XML document Insert new elements and attributes in the transformed document

XP New Perspectives on XML Tutorial 6 4 WORKING WITH XSL In 1998, the W3C developed the Extensible Style sheet Language, or XSL XSL is composed of three parts: –XSL-FO (Extensible Style sheet Language – Formatting Objects) –XSLT (Extensible Style sheet Language Transformations) –XPath XSL-FO is used to implement page layout and design XSLT is used to transform XML content into another presentation format XPath is used to locate information from an XML document and perform operations and calculations upon that content

XP New Perspectives on XML Tutorial 6 5 GENERATING A RESULT DOCUMENT An XSLT style sheet contains instructions for transforming the contents of an XML document into another format An XSLT style sheet document is itself an XML document An XSLT style sheet document has an extension.xsl An XSLT style sheet converts a source document of XML content into a result document by using the XSLT processor

XP New Perspectives on XML Tutorial 6 6 INTRODUCING XSLT STYLE SHEETS AND PROCESSORS The transformation can be performed by a server or a client In a server-side transformation, the server receives a request from a client, applies the style sheet to the source document, and returns the result document to the client In a client-side transformation, a client requests retrieval of both the source document and the style sheet from the server, then performs the transformation, and generates the result document

XP New Perspectives on XML Tutorial 6 7 CREATING AN XSLT STYLE SHEET To create an XSLT style sheet, the general structure: <xsl:stylesheet version = 1.0 xmlns:xsl =“ Content of the style sheet The tag can be substituted for the tag

XP New Perspectives on XML Tutorial 6 8 WORKING WITH DOCUMENT NODES Under XPath, each component in the document is referred to as a node, and the entire structure of the document is a node tree The node tree consists of the following objects: –the XML document itself –Comments – processing instructions –Namespaces –elements, –element text –element attributes

XP New Perspectives on XML Tutorial 6 9 NODE TREE EXAMPLE

XP New Perspectives on XML Tutorial 6 10 WORKING WITH DOCUMENT NODES At the top of the node is the root node A node that contains other nodes is called a parent node, and the nodes contained in the parent are called child nodes Nodes that share a common parent are called sibling nodes Any node below another node is referred to as a descendant of that node Nodes are distinguished based on the object they refer to in the document A node for an element is called an element node The node that stores element attributes is called an attribute node

XP New Perspectives on XML Tutorial 6 11 USING XPATH TO REFERENCE A NODE XPath provides the syntax to refer to the various nodes in the node tree The syntax is used by operation system to specify file pathnames The location of a node can be expressed in either absolute or relative terms XPath also does data extraction With a relative path, the location of the node is indicated relative to a specific node in the tree called the context node

XP New Perspectives on XML Tutorial 6 12 USING XPATH TO REFERENCE A NODE For absolute path, XPath begins with the root node, identified by a forward slash and proceeds down the levels of the node tree An absolute path: /child1/child2/child3/… To reference an element without regard to its location in the node tree, use a double forward slash with the name of the descendant node A relative path : //descendant

XP New Perspectives on XML Tutorial 6 13 REFERENCING GROUPS OF ELEMENTS XPath allows you to refer to groups of nodes by using the wildcard character (*) To select all of the nodes in the node tree, you can use the path: //* The (*) symbol matches any node, and the (//)symbol matches any level of the node tree Example: /portfolio/stock/*

XP New Perspectives on XML Tutorial 6 14 REFERENCING ATTRIBUTE NODES XPath uses different notation to refer to attribute nodes The syntax for attribute node where attribute is the name of the attribute Example:

XP New Perspectives on XML Tutorial 6 15 WORKING WITH TEXT NODES The text contained in an element node is treated as a text node The syntax for selecting a text node To match all text nodes in the document, use: //text()

XP New Perspectives on XML Tutorial 6 16 CREATING THE ROOT TEMPLATE A template is a collection of elements that define how a particular section of the source document should be transformed in the result document The root template sets up the initial code for the result document To create a root template, the syntax is: XSLT and Literal Result Elements

XP New Perspectives on XML Tutorial 6 17 CREATING A TEMPLATE To create a template, the syntax is: XSLT and Literal Result Elements where node is either the the name of a node from the source document’s node tree, or an XPath expression that points node in the tree A template contains two types of content: XSLT elements and literal result elements –XSLT elements are those elements that are part of the XSLT namespace and are used to send commands to the XSLT processor –A literal result element is text sent to the result document, but not acted upon by the XSLT processor

XP New Perspectives on XML Tutorial 6 18 CREATING THE ROOT TEMPLATE EXAMPLE

XP New Perspectives on XML Tutorial 6 19 SPECIFYING THE OUTPUT METHOD By default, the XSLT processor will render the result document as an XML file To control how the processor formats the source document, you can specify the output method using the element

XP New Perspectives on XML Tutorial 6 20 ATTRIBUTS OF THE ELEMENT

XP New Perspectives on XML Tutorial 6 21 TRANSFORMING A DOCUMENT A browser with a built-in XSLT processor allows you to view the result document Alternatively, you can use XML Spy to create the result document as a separate file, and then view that file in your browser Most XSLT processors provide the capability to create the result document as a separate file Internet Explorer 6.0 contains built-in XSLT processor You can view the results of the transformation by opening the result document in the browser

XP New Perspectives on XML Tutorial 6 22 INSERTING A NODE VALUE To insert a node’s value into the result document, the syntax is: – select=“XPath Expression” /> –where XPath Expression is an expression that identifies the node from the source document’s node tree If the node contains child elements in addition to text content, the text in those child nodes appears as well

XP New Perspectives on XML Tutorial 6 23 PROCESSING A BATCH OF NODES To process a batch of nodes, the syntax is: XSLT and Literal Elements where XPath Expression is an expression that defines the group of nodes to which the XSLT and literal result elements are applied

XP New Perspectives on XML Tutorial 6 24 WORKING WITH TEMPLATES To apply a template in the result document, use the XSLT element – where XPath Expression indicates the node template to be applied

XP New Perspectives on XML Tutorial 6 25 USING THE BUILT-IN TEMPLATES Each node has its own built-in template. The built-in template for element nodes matches the document root and all elements in the node tree The built-in template for text nodes matches all text nodes and causes their values to appear in the result document For example, you can add the stock template to the style sheet

XP New Perspectives on XML Tutorial 6 26 SORTING NODES By default, nodes are processed in document order, by their appearance in the document To specify a different order, XSLT provides the element This element can be used with either the or the element The element contains several attributes to control how the XSLT process sorts the nodes in the source document –The select attribute determines the criteria under which the context node is sorted –The data-type attribute indicates the type of data –The order attribute indicates the direction of the sorting (ascending or descending)

XP New Perspectives on XML Tutorial 6 27 CREATING CONDITIONAL NODES XSLT supports two kinds of conditional elements: – To apply a format only if a particular condition is met, use the element To test for multiple conditions and display different outcomes, use the element

XP New Perspectives on XML Tutorial 6 28 USING COMPARISON OPERATORS AND FUNCTIONS

XP New Perspectives on XML Tutorial 6 29 WORKING WITH PREDICATES Predicates are XPath expressions that test for a condition and create subsets of nodes that fulfill that condition The predicate can also indicate the position of the node in the node tree To select a specific position in the source document, use the position() function combined with any XPath expression

XP New Perspectives on XML Tutorial 6 30 CREATING ELEMENTS AND ATTRIBUTES To create an element, XSLT uses the tag The namespace attribute assigns a name to the element The namespace attribute provides a namespace The use-attribute provides a list of attribute-sets To create the element in the result document, use the tag

XP New Perspectives on XML Tutorial 6 31 CREATING AN ATTRIBUTE Attributes are created in XSLT by using the element The name attribute specifies the name of the attribute The namespace attribute indicates the namespace You can create inline images in the result document by using the attribute tag To add the href attribute to the tag, use the element

XP New Perspectives on XML Tutorial 6 32 CREATING COMMENTS AND PROCESSING INSTRUCTIONS The element creates the comment You can create a processing instruction by using the element If you want to add a processing instruction to attach the result document to the style.css sheet, use the following code:

XP New Perspectives on XML Tutorial 6 33 SUMMARY Extensible Style sheet Language,or XSL, is composed of three parts: XSL- FO, XSLT, and XPath XPath language is used to reference a node Templates are used to format sections of the XML document and transform XML data into a variety of formats Nodes can be sorted in either alphabetical or numerical order Comparison elements allow changing the contents of the result document based on the values of the nodes in the source document Predicates are used to create subsets of the source document’s node tree You can insert new elements and attributes in the transformed document