SD2520 Databases using XML and JQuery

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

XML: Extensible Markup Language
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
Introduction to XSLT. What is XML? Design Goals of XML XML Format XML Declaration ElementsAttributes.
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.
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.
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 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.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
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.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
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.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
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,
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.
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)
August Chapter 6 - XPath & XPointer Learning XML by Erik T. Ray Slides were developed by Jack Davis College of Information Science and Technology.
Database Systems Part VII: XML Querying Software School of Hunan University
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.
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.
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.
Session II Chapter 3 – Chapter 3 – XPath Patterns & Expressions Chapter 4 – XPath Functions Chapter 15 – XPath 2.0http://
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.
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.
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.
XML DOM Week 11 Web site:
CITA 330 Section 5 XPath. XSL XSL (Extensible Stylesheet Language) is the standard language for writing stylesheets to transform XML documents among different.
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.
Beginning XML 4th Edition.
Querying and Transforming XML Data
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML Path Language Andy Clark 17 Apr 2002.
Presentation transcript:

SD2520 Databases using XML and JQuery Writing XPath Queries SD2520 Databases using XML and JQuery

XPath Patterns and Expressions When you create a template, you use a pattern to specify the nodes that the template can be applied to. When you apply a template, you use an expression to specify the node set that should be processed. You write both patterns and expressions using XML Path Language (XPath) syntax.

XPath XPath is a language for selecting nodes and node sets by specifying their location paths in the XML document You can also use XPath in other XSLT instructions to further process given node sets to return values instead of nodes. XPath has built-in functions to do math, process strings, and test conditions in an XML document.

Like XSLT, XQuery uses XPath expressions. Note: Like XSLT, XQuery uses XPath expressions. The most current version of the language is XPath 2.0. However, because version 1.0 is still more widely used, will cover XPath 1.0. in two chapters

LOCATING NODES At the foundation of the XPath language is the ability to use location paths to refer to a node or node set. A node is an individual piece of the XML document (such as an element, an attribute, or some text content). A location path uses relationships to describe the location of a node or set of nodes relative to a given node. When translating location paths, XPath considers all XML documents as tree structures. They are considered node trees, which are a hierarchical structure of nodes (see Figures 10-1 and 10-2 next).

Figure 10.1 Figure 10.2

The XML Node Tree In an XML node tree, everything in the tree is a node, and every node is in some way related to another. At the top of the node tree is the root node. The root node, or document node, can have any number of child nodes. To these child nodes, the root node is a parent node. These child nodes can have any number of child nodes themselves, and so on, and so on.

The XML Node Tree Child nodes with the same parent are called sibling nodes. Descendant nodes are a node’s child nodes, its children’s child nodes, and so forth. Ancestor nodes are a node’s parent node, grandparent nodes, etc. Through XPath location paths, you can access any of these nodes from any other simply by knowing the re-lationship between the two.

Location Paths There are two kinds of location paths: relative location paths and absolute location paths. A relative location path consists of a sequence of location steps separated by / (a forward slash). Each step selects a node or node set relative to the current node. Then, each node in that set is used as the current node for the following step, and so on. An absolute location path consists of / (a forward slash), optionally followed by a relative location path. A / by itself selects the root node of the XML document. If it is followed by a relative location path, then the location path is a relative location path starting at the root node.

Using Located Nodes Often, when using location paths, you will be using the located node or node set as a container of other elements to process. Other times, you will want to know the node’s value. In XPath, there are seven different node types: root nodes (of which there is always exactly one) element nodes text nodes attribute nodes comment nodes processing instruction nodes namespace nodes. For each node type, there is a way of retrieving its value. For some, the value is part of the node itself; for others, the value is based on the value of its descendant nodes.

* * Important TIP * * The XPath language syntax was inspired in part by the common “path/file” file system. The current node is the element, or node, that is currently being processed. The context node is where the XPath location path address starts. In most circumstances, these terms are interchangeable, so the term current node is used throughout the book.

DETERMINING THE CURRENT NODE As the XSLT processor goes through your style sheet, it works on one node at a time. It is through the use of the xsl:template xsl:apply-templates xsl:for-each elements that it knows which parts of your XML document to process and when. When developing an XSLT style sheet, you will often specify what to process next with respect to what is being processed now. The node currently being processed is called the current node. Before you can refer from the current node, you will need to know how to identify it (Figure 10-3 next Slide).

FIGURE 10-3 At point 1, the current node is / (the root node) as specified by the xsl:template match=”/” instruction. When the processor reaches point 1a, the current node becomes the first wonder element in ancient_wonders and the processing jumps to point 2 where that wonder element is processed according to the xsl:template match=”wonder” instruction.

FIGURE 10-3 Then, when the processor reaches point 2a, the name element with a language attribute not equal to English becomes the current node and the processing jumps to point 3, where that name element becomes the current node and is processed according to the xsl:template match=” name[@language!=’English’]” instruction.

FIGURE 10-3 When this instruction is complete, the processor “returns” from the name template applied in point 2a. The current node then becomes the wonder element once again, until the processor finishes the wonder template and returns to the root template.

FIGURE 10-3 After this first wonder element is processed, the second wonder element becomes the current node, and so on until all the wonder elements have been processed (and taken their turn as the current node)

To determine the current node: By default, the current node is the one that is specified by the current template. In other words, the current node is identified by the template’s match attribute. If there is an xsl:apply-templates instruction, the current node becomes the node that is matched by the corresponding template (that is, the one specified in the match attribute of the xsl:template instruction). When the processor “returns” from that xsl:template, the current node reverts back to one from the original template’s match attribute.

* * Tips * * The xsl:apply-templates instruction may process more than one node in the case where the select expression returns a node set. You won’t always want to select the entire node set. To get a subset of the current node, you can add a test called a predicate. You can also use . (the current node shortcut) in a predicate to refer to the context node. The context node is the node that is being tested by the predicate.

REFERRING TO THE CURRENT NODE If you’re currently processing the node that you want to use in a select attribute, there’s a shortcut you can use. Instead of referencing the current node using a location path from the root node, it’s much easier to use the current node shortcut (Figure 10-4)