CSE3201/CSE4500 Information Retrieval Systems

Slides:



Advertisements
Similar presentations
Internet Technologies1 1 Lecture 4: Programming with XSLT.
Advertisements

Managing Data Exchange: XPath
Transforming XML Part I Document Navigation with XPath John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
XPath Eugenia Fernandez IUPUI. XML Path Language (XPath) a data model for representing an XML document as an abstract node tree a mechanism for addressing.
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)
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
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.
XPath Tao Wan March 04, What is XPath? n A language designed to be used by XSL Transformations (XSLT), Xlink, Xpointer and XML Query. n Primary.
Cornell CS 502 More XML XML schema, XPATH, XSLT CS 502 – Carl Lagoze – Cornell University.
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)
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.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
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.
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
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.
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.
XPath XPath is used to navigate through elements and attributes in an XML document. XPath is a major element in W3C's XSLT standard - and XQuery and XPointer.
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.
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 XPath XPath became a W3C Recommendation 16. November 1999 XPath is a language for finding information in an XML document XPath is used to navigate through.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
XPath Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
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.
Lecture 11 XSL Transformations (part 1: Introduction)
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.
 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 – XSL: Extensible Stylesheet Language Transformations (XSLT) Outline 12.1Introduction 12.2Setup.
SDPL 2001Notes 5: XSLT1 5. Document Transformations n XSLT (W3C Rec. Nov-99) –A language for transforming XML documents »representative of features common.
ACG 6415 XSLT Presenting XML and XBRL. Re-Purpose  The main benefit of XML / XBRL Reusability of Data contained in Instance Document We need a method.
XPath Presented by Kushan Athukorala. 2 Agenda XPath XPath Terminology Selecting Nodes Predicates.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
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.
Session II Chapter 3 – Chapter 3 – XPath Patterns & Expressions Chapter 4 – XPath Functions Chapter 15 – XPath 2.0http://
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations Presenting XML and XBRL.
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: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
1 XPath. 2 Agenda XPath Introduction XPath Nodes XPath Syntax XPath Operators XPath Q&A.
XSLT I Robin Burke ECT 360. Outline History / Terminology XSLT processing XSLT syntax XPath XSLT basics Lab.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations Presenting XML and XBRL.
CITA 330 Section 5 XPath. XSL XSL (Extensible Stylesheet Language) is the standard language for writing stylesheets to transform XML documents among different.
Displaying Data with XSLT ©NIITeXtensible Markup Language/Lesson 6/Slide 1 of 45 Objectives In this lesson, you will learn to: * Perform conditional formatting.
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.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
Beginning XML 4th Edition.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations
XML Path Language Andy Clark 17 Apr 2002.
XML WITH CSS.
More XML XML schema, XPATH, XSLT
Presentation transcript:

CSE3201/CSE4500 Information Retrieval Systems XPath and XSLT CSE3201/CSE4500 Information Retrieval Systems

Manipulating XML Documents parser data Applications

What is XSL Extensible Stylesheet Language Developed by W3C XSL Working Group Motivation: to handle the manipulation and presentation of XML documents Consists of: XSLT and XSL-FO

XSL Presentation document Transformation process XML document Stylesheet processor XML document XSL document Presentation document Transformation process

Transformation Tools XPath XSL(Extensible Stylesheet Languages) XSLT(XSL Transformation) XSL-FO(XSL Formatting Object)

Transformation Process

XSLT Processing Type of processings: Output Uses Change of vocabulary Reorder data elements Combine data elements Filter and exclude data elements Output Other XML vocabularies or fragments Non-XML formats Uses Display and printing Transformation of data

XPath A locator for items in XML document. XPath expression gives direction of navigation in XML document. Assume an XML document as a “tree” Any part of a document, eg element, attribute, is considered as a “node” Current version XPATH 1.0

XPath Syntax (full form): Axis Node test Predicate: describing the relationship between nodes, eg child, parents, etc. Node test condition for selecting nodes. Predicate: further condition refinement of the set of nodes resulted from the node test.

XPath Axes context node Ancestor Parent/ancestor sibling node child/descendant descendant attribute context node

Node Test A node test identifies nodes in the document that meet the criteria of the test. The simplest type of test is nodes that match an element name. Example: child::book => to find any child element with the name “book”. child::author

Predicate Predicate further refine or filter the node-set produced by the node test. Example: Find the third book in the list child::book[position( )=3] Find all the books that has <isbn> element child::book[isbn]

Abbreviations Formal Short Description child::book book Select all children of the context node that has <book> element nodes. child::* * Select all element nodes of the context node. self::node() . Select the context node. parent::node() .. Select the parent of the context node. child::book[position()=1] Book[1] Select the first child element that has <book> element. attribute::* @* select all the attributes of the context node attribute::number @number Find the number of attributes in the context node.

Location Path Uses “/” to build path, eg Document Root /name/first “John” <middle> “Little” <last> “Howard”

Relative vs Absolute Path full path needs to be included, starting from the root node. eg: /name/first Relative Path path is declared starting from the current context node. eg: assume our current context is “name”, the XPath expression for the node first => first

Recursive Decent Operator Locating nodes based on their names, regardless of where their positions in the document. Uses “//” Example: //first Select any <first> element in the document (regardless how far down the tree). Decrease the performance of the stylesheet. The entire document must be searched by the XSLT parser.

Filtering Nodes It is done using XPath’s predicate. the “[ ]” symbol. Using element as a filter: book[price] matches any <book> element that has a <price> child element. Using attribute as a filter: book[@id] matches any <book> element that has an id attribute.

XPath Expression Some possible operators to build an XPath Expression: and Logical AND or Logical OR not() logical negation = Equal != Not equal < Less than <= Less than equal > Greater than >= Greater than equal | Union

XPath Expression - Examples <xsl:template match="/"> <xsl:if test=“not(position()=last())”>

Usage of XPath in XSLT XSLT uses XPath expression to: Match node sets in order to execute templates. Evaluate node sets to control execution of conditional XSLT elements. Select node sets to change current context and direct the flow of the execution through the source document. Select node sets to obtain an output value Professional XML, page 379.

XPath Function XPath functions can be used to: manipulate node set eg: count, last, name, position manipulate string eg: concat, substring, contains test boolean value eg: language, false, true perform numeric operations eg: ceiling, floor, number, round, sum XSLT specific manipulation eg: current

XPath Function - Examples <xsl:if test=“not(position()=last())”> substring(‘abcde’,2,3) => returns ‘bcd’

Structure of Stylesheet An XSLT stylesheet is an XML document. Root element is stylesheet element <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> … </xsl:stylesheet> Consists of a set of rules. Rules are made up of patterns and templates.

Attaching an XSL to an XML doc <?xml-stylesheet type="text/xsl" href="books.xsl"?> href refers to the filename of the XSL document.

Example of a Stylesheet <bookshop> <book> <title> Harry Potter and the Sorcerer stone </title> <author> <initials>J.K</initials> <surname> Rowling</surname> </author> <price value=“$16.95”></price> </book> … </bookshop> <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <body> <h1>Book</h1> <xsl:value-of select="bookshop/book/title"/> </body> </html> </xsl:template> </xsl:stylesheet>

Selecting Output Type Possible outputs: Syntax: XML, HTML, Text <xsl-output method=“xml”/> <xsl-output method=“text”/> <xsl-output method=“html”/>

Templates To create a template, we need: To declare the location in the source tree where the template will be applied. Rules of matching to be applied. can be another template The location is declared using the XPath expression.

Using Templates Templates are called using the <xsl:apply template>. <xsl:apply-templates   select = node-set-expression>  </xsl:apply-templates> The “select” attribute is optional. Without the “select” attribute, the XSL processor will apply the templates to all the child elements of the current context node.

Template Examples <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/bookshop/book"> <html> <body> <h1>Book</h1> <xsl:apply-templates/> </body> </html> </xsl:template> </xsl:stylesheet>

Selecting Templates <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <body> <h1>Monash Bookshop</h1> <xsl:apply-templates select="bookshop/book"/> </body> </html> </xsl:template>

Selecting Templates- cont’d <xsl:template match="book" > <xsl:apply-templates select="author"/> </xsl:template> <xsl:template match="author"> <h2>Author</h2> <xsl:value-of select="."/> </xsl:stylesheet>

Getting the Value of a Node xsl:value-of select=XPath expression Example: <xsl:template match="bookshop/book"> <p><xsl:value-of select="title"/></p> </xsl:template>

Conditional Test xsl:if Example: there is no “else” statement. takes one attribute, test, which is an XPath expression. if it evaluates true, the body of the element is executed Example: <xsl:if test=“@id”> …</xsl:if>

Iteration <xsl:for-each> <xsl:template match="/"> <html> <body> <h1>Book</h1> <xsl:for-each select="/bookshop/book"> <p> <xsl:value-of select="title"/> </p> </xsl:for-each> </body> </html> </xsl:template> <html> <body> <h1>Book</h1> <p> Harry Potter and the Sorcerer Stone</p> <p> Harry Potter</p> </body> </html>

Making Copies xsl:copy It does not copy any child nodes that the context node may have. xsl:copy-of copies all <xsl:template match="/bookshop"> <html> <body> <h1>Book</h1> <xsl:copy/> </body> </html> </xsl:template> <html> <body> <h1>Book</h1> <bookshop></bookshop> </body> </html>

Copy-of <?xml version="1.0"?> <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:output method="xml"/> <xsl:template match="/"> <xsl:element name="Author_List"> <xsl:apply-templates/> </xsl:element> </xsl:template> <xsl:template match="bookshop/book"> <xsl:copy-of select="author"/> </xsl:stylesheet> <?xml version="1.0" encoding="utf-8"?> <Author_List> <author> <initials>JK</initials> <surname> Rowling</surname> </author> <initials>J</initials> </Author_List>