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.

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.
Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: XPath, NameSpaces.
Dr. Alexandra I. Cristea XPath and Namespaces.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSLT (eXtensible Stylesheet Language Transformation) 1.
Introduction to XSLT. What is XML? Design Goals of XML XML Format XML Declaration ElementsAttributes.
Transforming XML Part I Document Navigation with XPath John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
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.
eXtensible Stylesheet Language
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.
A note on generating text with the xsl:value-of instruction.
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)
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.
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Overview of XPath Author: Dan McCreary Date: October, 2008 Version: 0.2 with TEI Examples M D.
SD2520 Databases using XML and JQuery
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.
10/06/041 XSLT: crash course or Programming Language Design Principle XSLT-intro.ppt 10, Jun, 2004.
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.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
Introduction to XPath Web Engineering, SS 2007 Tomáš Pitner.
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.
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,
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.
Li Tak Sing COMPS311F. XPath XPath is a simple language that allows you to write expressions to refer to different parts of an XML document. We will learn.
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 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)
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.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Applying eXtensible Style Sheets (XSL) Ellen Pearlman Eileen Mullin Programming.
ITB Web programming for E- Commerce 1 ITB6227 Programming for E-COMMERCE Lecture Presentation of XML Documents.
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.
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
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.
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.
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.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations Presenting XML and XBRL.
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.
XSLT, XML Schema, and XPath Matt McClelland. Introduction XML Schema ▫Defines the content and structure of XML data. XSLT ▫Used to transform XML documents.
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.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
Querying and Transforming XML Data
XML WITH CSS.
Presentation transcript:

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 of the XML document, It provides the ability to navigate around the tree, selecting nodes by a variety of criteria. In popular use an XPath expression is often referred to simply as "an XPath".

XPath XPath is not itself written as XML, but is used heavily in XSLT XPath is almost a small programming language; it has functions, tests, and expressions XPath is always used in conjunction with XSLT

Refresher about XSLT XSLT is XML, so it needs an XML declaration like this: This XML implements the XSLT namespace:

Parts of XSLT File The XML text document is read into the parser and stored as a tree of nodes In the first step of this transformation, the XSLT processor analyzes the XML document and converts it into a node tree. The Root Template is written as such: and selects the entire tree of nodes

Xpath Everything in the document tree is a node, and is accessible via XPath XPath is a language for locating nodes in an XML document Locate nodes – Root – Element – Text – Attribute – And more

XPath Like Computer Directories C:\Documents and Settings\Teresa\My Documents\Computer Class

XML Node Tree

This statement matches the entire XML document – It matches the root node – It brings the entire document tree into the processors memory

Forward and backward Slashes The “/” is used frequently in Unix like command interface or “Shell” The forward slash is a way to select what level to search in the file system If you are using Windows Explorer, you would use a “\” (backward slash) for designating where in the file system. For us, the “/” let’s us easily navigate the tree of nodes in an XML document

Ways to Locate Nodes XPath is a language for selecting nodes and node sets As with the name, XPath creates paths to nodes Paths may be:Relative or Absolute

Absolute Paths ….

Relative Paths

Determining the “Current Node” A relative path is based on its current node A forward slash or “/” is used to designate each node “level” in the path Whatever the current template is in the xsl document, is the current node will make the root node of the xml document the current node

Current or Context node cont. A shortcut to getting current node or context node “.” Just type a period rather than typing in the path that you need You can type “..” two periods to get the current node’s parent nodes. “/” Selects the root node (entire document) “//” Selects children nodes from the current node Selects attribute nodes

XPath Nodes Root Node Element Node Attribute Node Text Node Comment Node Processing Instruction Node Namespace Node

Example / Traversing the Tree of Nodes Context Node

Current Node “.” Prints the value of name if its attribute is not equal to English <xsl:template match= ( )

Path Result bookstore Selects all nodes with the name "bookstore" /bookstore Selects the root element bookstore Note: If the path starts with a slash ( / ) it always represents an absolute path to an element! bookstore/book Selects all book elements that are children of bookstore //book Selects all book elements no matter where they are in the document

Predicates Predicates are used to find a specific node or a node that contains a specific value.

XSL “functions” Review These are all written in xml that allow us to manipulate and move around the document –xsl:value-of –xsl:for-each –xsl:choose –xsl:sort –xsl:if

XPath Functions Besides selecting nodes, can do other types of processing. These are real functions just like ones used in other general programming languages The functions are used to basic processing to nodes and their values But, it also built in functions that make our lives easier

Functions and Operators count() sum() round() format number() div division * multiplication + addition and more…

count() Of these wonders, <xsl:value-of select=" count(ancient_wonders/wonder/ history/how_destroyed[. = 'earthquake'])" /> were destroyed by earthquake, <xsl:value-of select=" count(//how_destroyed[. = 'fire'])"/> were destroyed by fire, and <xsl:value-of select=" count(//wonder) - count(//how_destroyed)" /> is still standing. ‘//’ Selects all Descendants of the Context Node

* for Multiplication <xsl:value-of select= "height"/> feet (<xsl:value-of select= "height * "/> m)

round() Robert King London Overseas XML Doc HTML doc XSLT doc

sum() <xsl:value-of select=“ format-number( sum(/ancient_wonders/wonder/height) div count(/ancient_wonders/wonder/height[.!=0]),'##0.0')" /> ft Value of Current node

format-number() <xsl:value-of select=“ format-number( sum(/ancient_wonders/wonder/height) div count(/ancient_wonders/wonder/height[.!=0]),'##0.0')" /> ft

current() Displays current node Current node: