Transforming XML XMLNamespaces, XSLT. XML Namespaces Sometimes it is necessary to mix XML elements –Different types of content –Use of markup to convey.

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

Chungnam National University DataBase System Lab
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.
XML Schema Heewon Lee. Contents 1. Introduction 2. Concepts 3. Example 4. Conclusion.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
Internet Technologies1 1 Lecture 4: Programming with XSLT.
17 Apr 2002 XML Namespaces Andy Clark. The Problem Documents use different vocabularies – Example 1: CD music collection – Example 2: online order transaction.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
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.
An Introduction to XML Based on the W3C XML Recommendations.
XSL XSLT and XPath 11-Apr-17.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
Tutorial 9 Working with XHTML
Processing XML Processing XML using XSLT Processing XML documents with Java (DOM) Next week -- Processing XML documents with Java (SAX)
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
Internet Technologies XSLT Processing XML using XSLT Using XPath Escaping to Java.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Object Oriented Programming III1 XSLT Processing XML using XSLT Using XPath.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Internet Technologies1 XSLT Processing XML using XSLT Using XPath.
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 XML. ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard.
Working with Namespaces Combining XML Vocabularies in a Compound Document.
WORKING WITH NAMESPACES
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
Scientific Markup Languages Birds of a Feather A 10-Minute Introduction to XML Timothy W. Cole Mathematics Librarian & Professor of.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
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
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
XML TUTORIAL Portions from w3 schools By Dr. John Abraham.
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 "
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter X IXXXXXXXXXX XXXXXX.
CIS 375—Web App Dev II XSL. 2 XSL Introduction XSL stands for _____________________________. XSL is the language used for manipulating and displaying.
Lecture 11 XSL Transformations (part 1: Introduction)
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
XP New Perspectives on XML, 2nd Edition Tutorial 2 1 TUTORIAL 2 WORKING WITH NAMESPACES.
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 Basics A brief introduction to XML in general 1XML Basics.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
COP 3813 Intro to Internet Computing Prof. Roy Levow XML.
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.
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 Tutorial 9New Perspectives on HTML and XHTML, Comprehensive 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
Tutorial 9 Working with XHTML. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Describe the history and theory of XHTML.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
 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:
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
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.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
XML Namespaces In this first lesson XML Namespaces, you will learn to:
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
Unit 4 Representing Web Data: XML
Chapter 7 Representing Web Data: XML
Chapter X IXXXXXXXXXXXXXXXX.
Presentation transcript:

Transforming XML XMLNamespaces, XSLT

XML Namespaces Sometimes it is necessary to mix XML elements –Different types of content –Use of markup to convey meta-information Some documents combine markup from different XML languages But: –Elements and attributes from different XML languages may share the same name –Need to group elements for processing

XML Namespaces XML Namespaces is the xml standard for distinguishing xml elements Namespaces are represented by attributes Elements from the same namespace can be recognised by software as a group Unique namespaces are defined by a URI

URL, URN, URI URL: a Uniform Resource Locator specifies the mechanism by which a resource is accessed e.g. URN: a Uniform Resource Name a unique sequence of characters naming an internet resource e.g. urn:Turquoise.Inflatable.Walrus the name has persistence even if the resource becomes unavailable URI –uniform resource identifier a URL or a URN (see RFC 2396 at

the namespace prefix short string representing the namespace URI distinguishes element and attribute names defined using an xmlns:prefix attribute – a prefixed element name is called a qualified name, or QName, or a raw name QName syntax prefix:local_part

example SVG and MathML both contain a set element Both SVG and MathML can be embedded in XHTML documents prefixes svg and mathml are used to distinguish the set elements distinct from

example 2: xml with multiple namespaces <html xmlns= xmlns:xlink= Three Namespaces Ellipse and Rectangle xlink prefix associated to the xlink namespace everywhere within the root element xhtml namespace associated to root html element and all descendants (no prefix needed) all (blue) elements are in the xhtml namespace xml declaration

xml with multiple namespaces <svg xmlns= width = 12cm height = 10cm> <rect x=4cm y=1cm width=3cm height=6cm> svg namespace associated to root svg element and all descendants (no prefix needed) all (red) elements are in the svg namespace

xml with multiple namespaces <p xlink:type=simple xlink:href=ellipses.html> More about ellipses <p xlink:type=simple xlink:href=rectangles.html> More about rectangles Last Modified 7th October 2003 all (blue) elements are in the xhtml namespace prefixed QNamed attributes (green) are in the xlink namespace

more on namespaces namespace can be defined in the element where it is used or in the root namespaces are identified by the URI, not the prefix used in a particular document the parser doesnt look up the URI – it is only there as a unique identifier!

more on namespaces namespaces are completely independent of DTDs QNames, if used, must be defined as elements in the DTD for them to be valid –parameter entities are used to get round this ingenious but awkward kludge not required for this module! namespaces important in XSLT documents

Introduction to XSLT

what is XSL? XML & client/server model –XML sits on server but does not do anything –XSL provides client views of data XSL: eXtensible Stylesheet Language –two separate namespaces XSL-FO (Formatting Objects) XSLT (Transformations) –X-Path used to navigate XML defines rules for transforming a source XML document into a target document

what is XSLT? Transforms source tree to results tree by: –Selecting elements –Selecting attributes –Rearranging elements –Sorting elements –Applying conditional tests XML/XSTL Similar to HTML/CSS

the XSLT transformation process XSLT document XSLT processor XML source output document set of template rules match elements and replace using template rules

a simple XSLT example the source

Alan Turing computer scientist mathematician cryptographer

Richard P Feynman physicist playing the bongoes

a simple XSLT example the transforming stylesheet

<xsl:stylesheet version = 1.0 xmlns:xsl= http :// xsl prefix identifies xsl QNames as belonging in the XSLT namespace associated to the given URI the empty stylesheet contains no template rules will apply default rules (see later)

a simple XSLT example the output of the transform

Alan Turing computer scientist mathematician cryptographer Richard P Feynman physicist playing the bongoes default behaviour strips out the mark up and returns a text document that reproduces the content of the XML (including whitespace like tabs and carriage returns) to modify the default behaviour, we add template rules that describe how to transform elements of the source document

template rules a template rule is defined by an element the match attribute contains a pattern identifying the input to which the rule is applied the content of the element is a template for the output from the matched pattern template

example 2 <xsl:stylesheet version = 1.0 xmlns:xsl= A Person

Alan Turing computer scientist mathematician cryptographer Richard P Feynman physicist playing the bongoes

example 2 output A Person Each person element in the original document has been replaced entirely by the template. The whitespace outside each person element has been preserved

example 3 <xsl:stylesheet version = 1.0 xmlns:xsl= A Person elements used in a template must preserve well-formedness of the document

example 3 output A Person The and tags have also been copied over from the template The whitespace outside each person element has been preserved

xsl:value-of xsl element which extracts the string value of an element in the source XML –the string value is the text content after: all tags have been removed entity and character references have been resolved select attribute specifies the element whose value is taken

example 4 <xsl:stylesheet version = 1.0 xmlns:xsl=

Alan Turing computer scientist mathematician cryptographer Richard P Feynman physicist playing the bongoes

example 4 output Alan Turing Richard P Feynman the full text content of the element after the,, and tags have been stripped out The whitespace inside each name element has been preserved along with the rest of the text content

example 4a <xsl:stylesheet version = 1.0 xmlns:xsl= -

example 4a output Alan Turing Richard P Feynman the value of attribute associated with element is added to the output

xsl element that can affect the default order of processing –which elements should be processed next –process elements in the middle of processing another element –prevent particular elements from being processed select attribute contains a pattern identifying elements to be processed at that point

example 5 <xsl:stylesheet version = 1.0 xmlns:xsl=

example 5 output Turing, Alan Feynman, Richard The order of processing has been changed. The output for each consists of the full text content of the, followed by a comma and a new line, followed by the full text content of the. The and elements are never processed because bypasses them

XSLT processor a software component that reads a XML source document and a stylesheet applies the transformation rules outputs the transformed document standalone SAXON Apache Xalan (used in NetBeans) built into a browser or application server MSXML (built in to IE6) Apache Cocoon (built in to Apache server)

Stylesheet Example – XML (catalog.xml) Empire Burlesque Bob Dylan USA Columbia ESSSSSSSSS Bruce Uk Cola

Stylesheet Example –XSL (cdcatalog.xsl) My CD Collection Title: Artist:

Stylesheet Example –Linking XML to Stylesheet Empire Burlesque Bob Dylan USA Columbia ESSSSSSSSS Bruce Uk Cola

My CD Collection Title: Empire Burlesque Artist: Bob Dylan Title: ESSSSSSSSS Artist: Bruce Stylesheet Example – HTML Output

Summary Namespaces – allow elements from different XML languages to be included in same XML –xmlns:xlink= XSLT – –Create templates with –Select content with –Control content with

Useful websites Standards: – administrates xsl std Tutorials/Forums – – – –