XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.

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

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.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
 2001 Prentice Hall, Inc. All rights reserved. 1.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
An Introduction to XML Based on the W3C XML Recommendations.
XML: Managing Data Exchange Stylesheets. Lesson Contents CSS The basic XSL file XSL transforms Templates Sort Numbering Parameters and Variables Datatypes.
+ XSL eXtensible Stylesheet Language. + 2 XML Lecture Adapted from the work of Prof Mark Baker ACET, University of Reading.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
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.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET (Using XSLT style sheet to calculate values based.
Tutorial 11 Creating XML Document
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
XP New Perspectives on XML, 2nd Edition Tutorial 2 1 TUTORIAL 2 WORKING WITH NAMESPACES.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
SD2520 Databases using XML and JQuery
XML 2nd EDITION Tutorial 2 Working With Namespaces.
WORKING WITH NAMESPACES
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
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
XSL XML Stylesheet Langauage. XPath Notation for addressing elements in an XML document /xyz - selects the root element /xyz/abc - selects all elements.
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.
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
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
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.
Fall 2006 Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 4 - XML.
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
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.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
Lecture 11 XSL Transformations (part 1: Introduction)
XP Tutorial 9 1 Working with XHTML. XP SGML 2 Standard Generalized Markup Language (SGML) A standard for specifying markup languages. Large, complex standard.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
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.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
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.
XP Tutorial 9New Perspectives on HTML and XHTML, Comprehensive 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
Grouping Robin Burke ECT 360. Outline Extra credit Numbering, revisited Grouping: Sibling difference method Uniquifying in XPath Grouping: Muenchian method.
Grouping Robin Burke ECT 360. Outline Grouping: Sibling difference method Uniquifying in XPath Grouping: Muenchian method Generated ids Keys Moded Templates.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
1 Lecture 7 Style Sheets: CSS. 2 Motivation HTML markup can be used to represent –Semantics: h1 means that an element is a top-level heading –Presentation:
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Digital Multimedia, 2nd edition Nigel Chapman & Jenny Chapman Chapter 14 This presentation © 2004, MacAvon Media Productions XML.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
5 Copyright © 2004, Oracle. All rights reserved. Navigating XML Documents by Using XPath.
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.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
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.
Unit 4 Representing Web Data: XML
WORKING WITH NAMESPACES
Extensible Markup Language XML
ACG 4401 XSLT Extensible Stylesheet Language for Transformations
Chapter 7 Representing Web Data: XML
Unit 6 - XML Transformations
Presentation transcript:

XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS

XP New Perspectives on XML, 2 nd Edition Tutorial 8 2 OBJECTIVES Work with step patterns to create complex node sets Create moded templates so that different code can be applied to the same nodes Access node sets using ID attributes and keys Access secondary source documents

XP New Perspectives on XML, 2 nd Edition Tutorial 8 3 WORKING WITH LOCATION PATHS Location path: –Expression that defines a path for the processor to navigate Default navigation direction: –Descendants only

XP New Perspectives on XML, 2 nd Edition Tutorial 8 4 STEP PATTERNS Allow processor to navigate node tree in different directions Syntax: axis::node-test[predicate] Sample: child::property[city=”Cutler”]

XP New Perspectives on XML, 2 nd Edition Tutorial 8 [age STEP PATTERN AXES Page 456

XP New Perspectives on XML, 2 nd Edition Tutorial 8 6 STEP PATTERN AXES CHARTS Page 458

XP New Perspectives on XML, 2 nd Edition Tutorial 8 7 WORKING WITH AXES Page 458

XP New Perspectives on XML, 2 nd Edition Tutorial 8 8 ELIMINATING DUPLICATES USING STEP PATTERNS Selecting duplicates: –listings/property[city=preceding::property/city] Excluding duplicates: –listings/property[not(city=preceding::property/city)] <xsl:apply-templates select=“listings/property[not(city=preceding::property/city)]”> |

XP New Perspectives on XML, 2 nd Edition Tutorial 8 9 SELECTING DUPLICATE CITIES

XP New Perspectives on XML, 2 nd Edition Tutorial 8 10 SELECTING FIRST OCCURANCE OF EACH CITY

XP New Perspectives on XML, 2 nd Edition Tutorial 8 11 CREATING MODED TEMPLATES Apply different styles to the same node set in the source document Syntax: styles Sample: </xsl: template

XP New Perspectives on XML, 2 nd Edition Tutorial 8 12 CALLING A MODED TEMPLATE Syntax: Sample: <xsl:apply-templates select=“listings/property[not(city=preceding::property/city)]” mode=“cityList”> When the XSLT processor encounters this element, it applies the template for the property node set under the cityList mode.

XP New Perspectives on XML, 2 nd Edition Tutorial 8 13 USING A MODED TEMPLATE Page 464

XP New Perspectives on XML, 2 nd Edition Tutorial 8 14 WORKING WITH IDS Using predicates to match data: –Sample: –Can be inefficient –Processor searches document for matching node named property with specified rln attribute –Result not stored anywhere Using IDs and keys results in more efficient searches

XP New Perspectives on XML, 2 nd Edition Tutorial 8 15 WORKING WITH IDS ID is declared in DTD: –Syntax: or –Sample: Requires the processor to verify that all attributes declared as IDs have unique values All ID values must be unique even if they belong to different elements

XP New Perspectives on XML, 2 nd Edition Tutorial 8 16 WORKING WITH IDS Processor creates an index of IDs Xpath function to search the ID index is : –Syntax: id(value) –Sample: id(“r317087”)

XP New Perspectives on XML, 2 nd Edition Tutorial 8 17 PROBLEMS WITH IDS When using non-validating parser, id() function returns empty result IDs can only be attributes IDs must be unique across all elements ID values must be valid XML names without spaces or special characters

XP New Perspectives on XML, 2 nd Edition Tutorial 8 18 WORKING WITH KEYS Keys: –Are declared in the style sheet, not in the DTD of the source document –Have names as well as values, allowing the style sheet author to create multiple distinct keys –Can be associated with node sets that contain attribute and element values –Can have values that are not limited to XML names

XP New Perspectives on XML, 2 nd Edition Tutorial 8 19 CREATING A KEY Syntax: Sample: The rlns key creates an index of all of the rlns attributes in the source document. Attribute of the property element

XP New Perspectives on XML, 2 nd Edition Tutorial 8 20 USING KEY() FUNCTION Syntax: key(“name”,“value”) Sample: key(“rlns”,“r317087”) which is equivalent to //property[rln=“r31787”] Keys can point to more than one node –Keys are not required to be unique

XP New Perspectives on XML, 2 nd Edition Tutorial 8 21 GENERATING IDS Create a unique id for a node Syntax: generate-id(node-set) Generated ids are constrained to be: –Same for the same node set –Different for different node sets Can be used to test for equality: –generate-id($nodes1)=generate-id($nodes2)

XP New Perspectives on XML, 2 nd Edition Tutorial 8 22 ORGANIZING NODES WITH MUENCHIAN GROUPING First formulated by Steve Muench of the Oracle Corporation Uses key() and generate-id() to create groups of nodes Worth considering when you need to organize data from a large source document

XP New Perspectives on XML, 2 nd Edition Tutorial 8 23 WORKING WITH MULTIPLE SOURCES Create a reference to another source document within a style sheet: –Syntax: document(object, base) –Example: document(“firms.xml”) Object is either: –URI of another XML source document, or –Node in the current source document that contains the URI of an external document that you want to access –E.g., firms.xml Base: –Defines base URI for resolving relative references –(element containing the URI of the source document Not supported by some browsers Optional

XP New Perspectives on XML, 2 nd Edition Tutorial 8 24 WORKING WITH MULTIPLE SOURCES

XP New Perspectives on XML, 2 nd Edition Tutorial 8 25 WORKING WITH MULTIPLE SOURCES Referencing elements: –document(“firms.xml”)/firms/city Good practice: –Create a variable for external document –Keep track of context node –Store values to be matched between documents in variables –Detailed example on pages

XP New Perspectives on XML, 2 nd Edition Tutorial 8 26 WORKING WITH MULTIPLE SOURCES

XP New Perspectives on XML, 2 nd Edition Tutorial 8 27 PLACING DATA INTO A STYLE SHEET Data element = data placed within a style sheet Some authors use data elements instead of external XML data sources because it is easier to manage a single file rather than several files. Data can be placed directly in style sheet Easier to manage a single file Data should be placed in its own namespace Data must be direct child of

XP New Perspectives on XML, 2 nd Edition Tutorial 8 28 PLACING DATA INTO A STYLE SHEET Example: <xsl:stylesheet version=“1.0” xmlns:xsl=“ xmlns:data=“ Karen Fawkes (608) …

XP New Perspectives on XML, 2 nd Edition Tutorial 8 29 PLACING DATA INTO A STYLE SHEET To access stylesheet data: –Syntax: document(‘ ’) –Sample: document(‘ ’)/xsl:stylesheet/data:agents/data:agent XSLT processors interpret the empty text string as a relative URL and access the current style sheet file Reference data agent elements

XP New Perspectives on XML, 2 nd Edition Tutorial 8 30 INSERTING CODE SNIPPETS Can be used to contain standard heading or banner HTML code placed in XHTML file To use: – Code snippets can be easily modified without having to edit the style sheets directly

XP New Perspectives on XML, 2 nd Edition Tutorial 8 31 SUMMARY Step patterns can be used with location paths to search the document in different orders Moded templates are used to define different instructions to be used with the same node pattern IDs and keys are used to create more efficient searches IDs can be generated using generate-id

XP New Perspectives on XML, 2 nd Edition Tutorial 8 32 SUMMARY Muenchian grouping uses key() and generate-id() to efficiently group nodes Multiple XML documents can be used by a stylesheet and opened with the document() function Data can be inserted directly into the stylesheet Code snippets can be placed in XHTML files and imported using document()