Object Oriented Programming III1 XSLT Processing XML using XSLT Using XPath.

Slides:



Advertisements
Similar presentations
XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
Advertisements

Transforming XML XMLNamespaces, XSLT. XML Namespaces Sometimes it is necessary to mix XML elements –Different types of content –Use of markup to convey.
Bottom-up Evaluation of XPath Queries Stephanie H. Li Zhiping Zou.
Internet Technologies1 1 Lecture 4: Programming with XSLT.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
+ XSL eXtensible Stylesheet Language. + 2 XML Lecture Adapted from the work of Prof Mark Baker ACET, University of Reading.
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.
Processing XML Processing XML using XSLT Processing XML documents with Java (DOM) Next week -- Processing XML documents with Java (SAX)
XSL Transformations (XSLT) Meghasyam Bokam April’1 st, 2002.
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 Transformations Lecture 8, 07/08/02. Templates The whole element is a template The match pattern determines where this template applies Result element(s)
1 Copyright (c) [2000]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents Roger L. Costello XML Technologies.
A technical introduction Felix Eickhoff XML Basics.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
Internet Technologies XSLT Processing XML using XSLT Using XPath Escaping to Java.
Lecture 12. Default Processing in XSLT The default processing in XSLT is to process the XPath root node The default processing for various node types.
Cornell CS 502 More XML XML schema, XPATH, XSLT CS 502 – Carl Lagoze – Cornell University.
CS 4408 Lecture 9. XSLT instruction elements We have seen that a template can contain non-XSLT text, canned text that it inserts into the result tree.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Internet Technologies1 XSLT Processing XML using XSLT Using XPath.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.
Overview of XPath Author: Dan McCreary Date: October, 2008 Version: 0.2 with TEI Examples M D.
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.
10/06/041 XSLT: crash course or Programming Language Design Principle XSLT-intro.ppt 10, Jun, 2004.
XSLT Brent P. Christie Major USMC. XSLT Overview  What is XSLT? –XSL is the Extensible Style Language. –It has two parts: the transformation language.
Navigating XML. Overview  Xpath is a non-xml syntax to be used with XSLT and Xpointer. Its purpose according to the W3.org is  to address parts of an.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
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.
CSE3201/CSE4500 Information Retrieval Systems
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XSLT and XPath, by Dr. Khalil1 XSL, XSLT and XPath Dr. Awad Khalil Computer Science Department AUC.
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
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 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Processing of structured documents Spring 2003, Part 7 Helena Ahonen-Myka.
XPath. Why XPath? Common syntax, semantics for [XSLT] [XPointer][XSLT] [XPointer] Used to address parts of an XML document Provides basic facilities for.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
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 part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
Lecture 11 XSL Transformations (part 1: Introduction)
IS432: Semi-Structured Data Dr. Azeddine Chikh. 6. XML Path (XPath)
XPath Aug ’10 – Dec ‘10. XPath   XML Path Language   Technology that allows to select a part or parts of an XML document to process   XPath was.
SDPL 2001Notes 5: XSLT1 5. Document Transformations n XSLT (W3C Rec. Nov-99) –A language for transforming XML documents »representative of features common.
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.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
CSE3201/CSE4500 XPath. 2 XPath A locator for items in XML document. XPath expression gives direction of navigation.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
XSLT I Robin Burke ECT 360. Outline History / Terminology XSLT processing XSLT syntax XPath XSLT basics Lab.
1 The XPath Language. 2 XPath Expressions Flexible notation for navigating around trees A basic technology that is widely used uniqueness and scope in.
5 Copyright © 2004, Oracle. All rights reserved. Navigating XML Documents by Using XPath.
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.
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.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
Seminar on Service Oriented Architecture
XML WITH CSS.
More XML XML schema, XPATH, XSLT
Presentation transcript:

Object Oriented Programming III1 XSLT Processing XML using XSLT Using XPath

Object Oriented Programming III2 Processing XML using XSLT XSLT is available on a number of platforms. Next week – how C# interacts with XSLT

Object Oriented Programming III3 The Catcher in the Rye J. D. Salinger Little, Brown and Company Input

Object Oriented Programming III4 <xsl:stylesheet xmlns:xsl=" version="1.0"> Processing

Object Oriented Programming III5 The Catcher in the Rye J. D. Salinger Little, Brown and Company Output

Object Oriented Programming III6 The Catcher in the Rye J. D. Salinger Little, Brown and Company Input

Object Oriented Programming III7 <xsl:stylesheet xmlns:xsl=" version="1.0"> The default rules matches the root, library and block elements.

Object Oriented Programming III8 The Catcher in the Rye J. D. Salinger Little, Brown and Company The output is the same.

Object Oriented Programming III9 The Catcher in the Rye J. D. Salinger Little, Brown and Company Cliff Notes on The Catcher in the Rye Two books in the input

Object Oriented Programming III10 <xsl:stylesheet xmlns:xsl=" version="1.0"> What’s the output?

Object Oriented Programming III11 The Catcher in the Rye J. D. Salinger Little, Brown and Company Cliff Notes on The Catcher in the Rye Illegal HTML

Object Oriented Programming III12 The Catcher in the Rye J. D. Salinger Little, Brown and Company Input

Object Oriented Programming III13 <xsl:stylesheet xmlns:xsl=" version="1.0"> <!-- --> We are not matching on publisher.

Object Oriented Programming III14 The Catcher in the Rye J. D. Salinger Little, Brown and Company We get the default rule matching the publisher and then printing its child.

Object Oriented Programming III15 The Catcher in the Rye J. D. Salinger Little, Brown and Company Input

Object Oriented Programming III16 <xsl:stylesheet xmlns:xsl=" version="1.0"> We can skip the publisher by matching and stopping the recursion.

Object Oriented Programming III17 The Catcher in the Rye J. D. Salinger

Object Oriented Programming III18 The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company A shelf has many books.

Object Oriented Programming III19 <xsl:stylesheet xmlns:xsl=" version="1.0"> Will this do the job?

Object Oriented Programming III20 The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company This is not what we want.

Object Oriented Programming III21 The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company Same input.

Object Oriented Programming III22 <xsl:stylesheet xmlns:xsl=" version="1.0"> Found a shelf Checks for a shelf and quits.

Object Oriented Programming III23 Found a shelf Output

Object Oriented Programming III24 The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company Same input.

Object Oriented Programming III25 <xsl:stylesheet xmlns:xsl=" version="1.0"> These are a few of my favorite books Produce a table of books.

Object Oriented Programming III26 These are a few of my favorite books 1 The Catcher in the Rye J. D. Salinger Little, Brown and Company 2 The XSLT Programmer's Reference Michael Kay Wrox Press 3 Computer Organization and Design Patterson and Henessey Morgan Kaufmann

Object Oriented Programming III27

Object Oriented Programming III28 XPATH Non-xml language used to identify particular parts of an xml document Used by XSLT for matching and selecting particular elements to be copied into the result tree. Used by Xpointer to identify a particular point in or part of an xml document that an Xlink links to. Slides adapted from “XML in a Nutshell” by Harold

Object Oriented Programming III29 XPATH First, we’ll look at three commonly used XSLT instructions: xsl:value-of xsl:template xsl:apply-templates

Object Oriented Programming III30 XPATH The xsl:value-of element computes the string value of an Xpath expression and inserts it into the result tree. XPath allows us to select nodes in the tree and different node types produce different values.

Object Oriented Programming III31 XPATH element => the text content of the element after all tags are stripped text => the text of the node attribute => the value of the attribute root => the value of the root processing-instruction => the processing instruction data (, and the target are not included comment => the text of the comment (no comment symbols) namespace => the namespace URI node set => the value of the first node in the set

Object Oriented Programming III32 XPATH The xsl:template top-level element is the key to all of xslt. The match attribute contains a pattern (location path) against which nodes are compared as they’re processed. If the pattern matches a node, then the contents are instantiated

Object Oriented Programming III33 XPATH Find and apply the highest priority template that matches the node set expression. If the select attribute is not present then all children of the context node are processed.

Object Oriented Programming III34 The Tree Structure of an XML Document Alan Turing computer scientist mathematician cryptographer See Harold Pg. 147

Object Oriented Programming III35 Richard M Feynman physicist Playing the bongoes Unicode ‘M’

Object Oriented Programming III36 / person born = “1914” died = “1952” id=“p342” person name first_name Alan <!– Did the word “computer scientist” exist in Turing’s day?”-- > profession

Object Oriented Programming III37 The root Element Nodes Text Nodes Attribute Nodes Comment Nodes Processing Instructions Namespace Nodes Nodes seen by XPath Constructs not seen by XPath CDATA sections Entity references Document Type Declarations

Object Oriented Programming III38 Note The following appears in each example below so it has been removed from the slides. <xsl:stylesheet xmlns:xsl=" version="1.0" > :

Object Oriented Programming III39 Location Paths The root matched the root matched the root

Object Oriented Programming III40 Location Paths Child element location paths (relative to context node) computer scientist

Object Oriented Programming III41 Location Paths Attribute location paths (relative to context node) 1912

Object Oriented Programming III42 Location Paths Attribute location paths (relative to context node)

Object Oriented Programming III43 Location Paths Comment Location Step (comments don’t have names) Did the word "computer scientist" exist in Turing's day?

Object Oriented Programming III44 Location Paths Comment Location Step comment deleted Document content with comments replaced as shown. Default – no comments output

Object Oriented Programming III45 Location Paths Text Location Step (Text nodes don’t have names) computer scientist

Object Oriented Programming III46 Location Paths Processing Instruction Location Step type="text/xsl" href = "pi.xsl"

Object Oriented Programming III47 Location Paths Wild cards There are three wild cards: *, The * matches any element node. It will not match attributes, text nodes, comments or processing instructions nodes.

Object Oriented Programming III48 Location Paths Matching with * Matches all elements and requests calls on sub-elements only. Nothing is displayed. The text nodes are never reached.

Object Oriented Programming III49 Location Paths Matching with node() The node() wild card matches all nodes: element nodes, text nodes, attribute nodes, processing instruction nodes, namespace nodes and comment nodes.

Object Oriented Programming III50 Matching with Node What is the output?

Object Oriented Programming III51 Matching with Node -Output

Object Oriented Programming III52 Location Paths Matching wild card matches all attribute nodes.

Object Oriented Programming III53 Matching Found an attribute What is the output?

Object Oriented Programming III54 Matching - Output Found an attribute 1912 Found an attribute 1954 Found an attribute p342 Found an attribute 1918 Found an attribute 1988 Found an attribute p4567

Object Oriented Programming III55 Matching p p4567

Object Oriented Programming III56 Location Paths Multiple matches with | Matches all the elements. Skips the text nodes unless they describe a profession or hobby.

Object Oriented Programming III57 Location Paths Selecting from all descendants with // // selects from all descendants of the context node as well as the context node itself. At the beginning of an Xpath expression, it selects from all descendants of the root node.

Object Oriented Programming III58 Location Paths Selecting from all descendants with // TuringFeynman

Object Oriented Programming III59 Location Paths Selecting from all descendants with // Alan

Object Oriented Programming III60 Location Paths Selecting from all descendants with // AlanRichard

Object Oriented Programming III61 Location Paths Selecting from all descendants with // Richard

Object Oriented Programming III62 Specifying the Child Axis Consider the following path: /Envelope/Header/Signature The above is an abbreviation for /child::Envelope/child::Header/child::Signature

Object Oriented Programming III63 Using an Axis

Object Oriented Programming III64 What is the output?

Object Oriented Programming III65 Richard M Feynman Alan Turing Axis Example - Output

Object Oriented Programming III66 Writing Output to an Attribute

Object Oriented Programming III67 Writing Output to an Attribute

Object Oriented Programming III68 Predicates In general, an Xpath expression may refer to more than one node. Predicates allow us to reduce the number of nodes we are interested in. Each step in a location path may have a predicate that selects from the node list that is current at that step in the expression. The boolean expression in the predicate is tested against each node in the context node list. If the expression is false then that node is deleted from the list.

Object Oriented Programming III69 Predicates Richard M Feynman

Object Oriented Programming III70 Predicates Richard M Feynman physicist Playing the bongoes

Object Oriented Programming III71 Predicates Alan Turing computer scientist mathematician cryptographer

Object Oriented Programming III72 Predicates Richard M Feynman physicist Playing the bongoes

Object Oriented Programming III73 Predicates <xsl:apply-templates select = < 1950]/ name[first_name='Alan']" /> Alan Turing

Object Oriented Programming III74 General XPath Expressions Xpath expressions that are not node sets can’t be used in the match attribute of an xsl:template element. They can be used for the values for the select attribute of xsl:value-of elements and in location path predicates.

Object Oriented Programming III75 General XPath Expressions

Object Oriented Programming III76 General XPath Expressions Xpath Functions Person Person 1 Person 2

Object Oriented Programming III77 General XPath Expressions Xpath Functions Mr. T. Mr. T. Alan Turing Node set converted to string