7 September 2005NVO Summer School 2005 - Aspen1 Advanced but ever-so-useful XML Technologies: Schema, XPath, XQuery, XSL an incomplete introduction Ray.

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

Chungnam National University DataBase System Lab
8 September 2006NVO Summer School Aspen1 Publishing and Resource Discovery with Registries Ray Plante Gretchen Greene T HE US N ATIONAL V IRTUAL.
7 September 2005NVO Summer School Aspen1 Advanced but ever-so-useful XML Technologies: Schema, XPath, XQuery, XSL an incomplete introduction Ray.
8 September 2008NVO Summer School 2008 – Santa Fe1 Publishing Data and Services to the VO Ray Plante Gretchen Greene T HE US N ATIONAL V IRTUAL O BSERVATORY.
Transforming XML XMLNamespaces, XSLT. XML Namespaces Sometimes it is necessary to mix XML elements –Different types of content –Use of markup to convey.
XML Schema Heewon Lee. Contents 1. Introduction 2. Concepts 3. Example 4. Conclusion.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
XML: Extensible Markup Language
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
An Introduction to XML Based on the W3C XML Recommendations.
1 COS 425: Database and Information Management Systems XML and information exchange.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Unit 4 – XML Schema XML - Level I Basic.
Introduction to XML This material is based heavily on the tutorial by the same name at
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
ECA 228 Internet/Intranet Design I Intro to XML. ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard.
Chapter 12 Creating and Using XML Documents HTML5 AND CSS Seventh Edition.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
Why XML ? Problems with HTML HTML design - HTML is intended for presentation of information as Web pages. - HTML contains a fixed set of markup tags. This.
Dr. Azeddine Chikh IS446: Internet Software Development.
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.
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.
XML Overview. Chapter 8 © 2011 Pearson Education 2 Extensible Markup Language (XML) A text-based markup language (like HTML) A text-based markup language.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Session IV Chapter 9 – XML Schemas
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter X IXXXXXXXXXX XXXXXX.
New Perspectives on XML, 2nd Edition
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
An OO schema language for XML SOX W3C Note 30 July 1999.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.
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.
Tutorial 13 Validating Documents with Schemas
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 1 of 36 Objectives In this lesson, you will learn to: * Declare attributes in an.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Unit 3 — Advanced Internet Technologies Lesson 11 — Introduction to XSL.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
CIS 228 The Internet 9/20/11 XHTML 1.0. “Quirks” Mode Today, all browsers support standards Compliant pages are displayed similarly There are multiple.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
16 May 2006IVOA Interoperability – Registries WG1 VOResource Schema v1.0 Release 6 Ray Plante NCSA T HE I NTERNATIONAL V IRTUAL O BSERVATORY A LLIANCE.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
1 XML and XML in DLESE Katy Ginger November 2003.
Product Training Program
Unit 4 Representing Web Data: XML
CIS 228 The Internet 9/20/11 XHTML 1.0.
XML QUESTIONS AND ANSWERS
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Chapter 7 Representing Web Data: XML
Chapter X IXXXXXXXXXXXXXXXX.
New Perspectives on XML
Presentation transcript:

7 September 2005NVO Summer School Aspen1 Advanced but ever-so-useful XML Technologies: Schema, XPath, XQuery, XSL an incomplete introduction Ray Plante T HE US N ATIONAL V IRTUAL O BSERVATORY

7 September 2005NVO Summer School Aspen2 XML Schema What it is: –A W3C* standard for defining and verifying an XML grammar An XML Schema document describes… –a set of legal XML tags and attributes, –what order they go in, and –what values are allowed. An XML Schema-aware XML parser can tell you if an XML document follows the rules of the grammar *World Wide Web Consortium Why you might care: –VO uses XML to encode metadata and service messages –XML Schema is used to define metadata encoding and message syntax –Ability to read XML Schema will help you understand what metadata is needed by an app and how to encode it VO end users and many developers will never need to know about Schema Can be helpful for debugging XML documents and messages What youll get from this session: –Rudimentary skills for reading an XML Schema document to discern the specified XML syntax –Understand the role of namespaces in supporting multiple schemas –A tool for validating an instance document

7 September 2005NVO Summer School Aspen3 Schema uses XML to describe syntax Contains a list of definitions –Elements and types –Attributes, groups, attribute-groups Types –Simple types: string, integer, dateTime, etc. The Astronomy Digital Image Library T07:45:00 –Complex types: contain other elements –Defining types Anonymous type – directly inside the definition of an element Global type – top-level definition, can be reused

7 September 2005NVO Summer School Aspen4 Namespaces Namespace: a schemas unique identifier –Set with the targetNamespace attribute –Used by an XML document to indicate which schema it is compliant with –URI format (URL or URN) Using a schema –Instance document: XML document that follows the grammar defined by the schema –xmlns attribute used to identify the default namespace that elements belong to –Tagging elements with namespace prefixes Prefix defined (anywhere) with xmlns: prefix xmlns:res= " " Prefixes attached to element/attribute name denotes it belongs to the associated schema … –Unqualified elements: a special technique for namespaces Tag the root element (or xsi:type) only Do not use xmlns Can make using multiple schemas easier

7 September 2005NVO Summer School Aspen5 Validating an instance document A validating parser can test whether an instance document is compliant with its schema xsi:schemaLocation attribute tells parser where to find Schema document(s) –Look-up list made up of namespace-location pairs xsi:schemaLocation= namespace file-or-URL … xsi:schemaLocation is just a recommendation –Parser may have local copies cached for more efficient parsing validate : a tool for validating XML documents against schemas

7 September 2005NVO Summer School Aspen6 Simple schema <xs:schema targetNamespace=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" minOccurs="0" maxOccurs="unbounded"> xmltech-simple.xsd

7 September 2005NVO Summer School Aspen7 <xs:schema targetNamespace=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" minOccurs="0" maxOccurs="unbounded"> Simple schema targetNamespace xmltech-simple.xsd

7 September 2005NVO Summer School Aspen8 Simple schema global = Direct child of xs:schema Only global elements can serve as a documents root element globally-defined element <xs:schema targetNamespace=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" minOccurs="0" maxOccurs="unbounded"> xmltech-simple.xsd

7 September 2005NVO Summer School Aspen9 Simple schema Anonymous type definition <xs:schema targetNamespace=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" minOccurs="0" maxOccurs="unbounded"> xmltech-simple.xsd

7 September 2005NVO Summer School Aspen10 Simple schema sequence : a list of elements that must appear in order choice : one from a list of elements may appear Other models: group, all, any Content model <xs:schema targetNamespace=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" minOccurs="0" maxOccurs="unbounded"> xmltech-simple.xsd

7 September 2005NVO Summer School Aspen11 Simple schema title: any string referenceURL : URI format type : restricted to a specified list of strings Locally-defined elements <xs:schema targetNamespace=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" minOccurs="0" maxOccurs="unbounded"> xmltech-simple.xsd

7 September 2005NVO Summer School Aspen12 Simple schema Default: minOccurs=1 maxOccurs=1 minOccurs=0: optional minOccurs=1: required Occurance restrictions <xs:schema targetNamespace=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" minOccurs="0" maxOccurs="unbounded"> xmltech-simple.xsd

7 September 2005NVO Summer School Aspen13 The compliant instance document <resource xmlns=" xmlns:xsi=" xsi:schemaLocation=" xmltech-simple.xsd" > NCSA Astronomy Digital Image Library Archive xmltech-simple.xml

7 September 2005NVO Summer School Aspen14 The compliant instance document Default namespace xmltech-simple.xml <resource xmlns=" xmlns:xsi=" xsi:schemaLocation=" xmltech-simple.xsd" > NCSA Astronomy Digital Image Library Archive

7 September 2005NVO Summer School Aspen15 The compliant instance document xsi namespace Prefix defined Default namespace xmltech-simple.xml <resource xmlns=" xmlns:xsi=" xsi:schemaLocation=" xmltech-simple.xsd" > NCSA Astronomy Digital Image Library Archive

7 September 2005NVO Summer School Aspen16 The compliant instance document xsi namespace Prefix defined Default namespace xsi:schemaLocation xsi:schemaLocation says, Load schema called from local file, xmltech-simple.xsd xmltech-simple.xml <resource xmlns=" xmlns:xsi=" xsi:schemaLocation=" xmltech-simple.xsd" > NCSA Astronomy Digital Image Library Archive

7 September 2005NVO Summer School Aspen17 The compliant instance document xsi namespace Prefix defined Default namespace xsi:schemaLocation xsi:schemaLocation says, Load schema called from local file, xmltech-simple.xsd xmltech-simple.xml <resource xmlns=" xmlns:xsi=" xsi:schemaLocation=" xmltech-simple.xsd" > NCSA Astronomy Digital Image Library Archive

7 September 2005NVO Summer School Aspen18 Global (Reusable) Types <xs:schema targetNamespace=" xmlns:res=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" type="res:Type" minOccurs="0" maxOccurs="unbounded"/> Define a prefix for the targetNamespace xmltech-globaltypes.xml

7 September 2005NVO Summer School Aspen19 Global (Reusable) Types Type defined here… <xs:schema targetNamespace=" xmlns:res=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" type="res:Type" minOccurs="0" maxOccurs="unbounded"/> Define a prefix for the targetNamespace xmltech-globaltypes.xml

7 September 2005NVO Summer School Aspen20 Global (Reusable) Types …and used here Type defined here… <xs:schema targetNamespace=" xmlns:res=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element name="type" type="res:Type" minOccurs="0" maxOccurs="unbounded"/> Define a prefix for the targetNamespace xmltech-globaltypes.xml

7 September 2005NVO Summer School Aspen21 Global (Reusable) Elements <xs:schema targetNamespace=" xmlns:res=" xmlns:xs=" elementFormDefault="qualified"> <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"/> <xs:element ref="res:type" minOccurs="0" maxOccurs="unbounded"/> Element defined here… …and used here xmltech-elrefs.xml

7 September 2005NVO Summer School Aspen22 Any entity or component of a VO application that is describable and identifiable by a IVOA Identifier. the full name given to the resource <xs:element name="referenceURL" type="xs:anyURI" minOccurs="0"> URL pointing to a human-readable document describing this resource. … Schema Documentation xmltech-documented.xml Most schema components can have documentation attached Documentation is important for defining metadata schemas Carnivore registry extracts documentation directly from schema for display to users

7 September 2005NVO Summer School Aspen23 Derived Types Two ways to derive a new type from an existing one –Extension Applicable only to complex types Adds additional elements or attributes to the content model <service xmlns=" created=" T12:00:00" > ADIL Query Page Archive

7 September 2005NVO Summer School Aspen24 Derived Types Two ways to derive a new type from an existing one –Restriction Simple types: restrict the legal values in some way Ex: integer: restrict range string: restrict to match a pattern Complex types: –Disallow optional elements, attributes –Restricting occurances –Setting default or fixed values where none were previously set

7 September 2005NVO Summer School Aspen25 Extending Schemas I: plugging-in derived entities Suppose you want to define an element in terms of a base type but allow any type derived from it to be inserted in its place –a form of polymorphism Two techniques –xsi:type a label in the instance document) –Substitution groups a label in the schema document

7 September 2005NVO Summer School Aspen26 Extending Schemas I: plugging-in derived entities xsi:type technique From our example… –The resource element has the type Resource –The Service type is derived from the Resource type –Declaring a service element is not necessary In the instance document… <resourceList xmlns=" NCSA Astronomy Digital Image Li Archive <resource xsi:type="Service" created=" T12:00:00" > ADIL Query Page Archive IVOA VOResource schema uses this technique In the schema document… <xs:element name="resource" type="res:Resource" maxOccurs="unbounded" />

7 September 2005NVO Summer School Aspen27 Extending Schemas I: plugging-in derived entities Substitution group technique From our example… –The Service type is derived from the Resource type –Add substitutionGroup attribute to service element definition means we can substitute service element anywhere a resource is allowed In the schema document… <xs:element name="service" type="res:Service" substitutionGroup="res:resource"> <xs:element ref="res:resource" maxOccurs="unbounded" /> In the instance document… <resourceList xmlns=" NCSA Astronomy Digital Image Li Archive ADIL Query Page Archive IVOA Space-Time Coordinates schema uses this technique

7 September 2005NVO Summer School Aspen28 separate schema file, separate namespace –Enables schema evolution in a backward compatible way. –Extension file uses xs:import to load schema being extended –Instance documents generally must define prefixes for both the original schema namespace and the extension namespace. Example: VOResource metadata schemas –Core metadata schema: VOResource –Extension schemas: VODataService, VORegistry, ConeSearch, SimpleImageAccess Extending Schemas II: placing extensions into a separate namespace

7 September 2005NVO Summer School Aspen29 A word about namespaces in instance documents…(FYI) An instance document must indicate what namespace(s) the elements belong to –So that the document can be validated –3 ways to indicate this controlled by elementFormDefault attribute in Schema file <xs:schema targetNamespace=" xmlns:res=" xmlns:xs=" elementFormDefault="qualified"> 1.Default namespace xmlns tags a whole section Advantages: Great for simple ns use Disadvantages: Can be confusing for authors when drawing on multiple schema 2.Namespace prefixes Invidually tag elements Advantages: Visually explicit about ns membership Can mix in elements from different ns with the same name. Disadvantages: Error-prone, ugly when drawing multiple schema 3.Unqualified: tag (global) root element Advantages: Single prefix tag needed at the top of the document; no other tags needed Good for when using multiple schemas together Least error prone Makes XPaths simpler Disadvantage: Cant have 2 elements from different ns w/same name elementFormDefault="qualified"elementFormDefault="unqualified" <resource xmlns=" … Archive <vr:resource xmlns:vr=" xmlns:cv=" … <vr:resource xmlns:vr=" … IVOA VOResource uses this technique

7 September 2005NVO Summer School Aspen30 A word about namespaces in instance documents…(FYI) An instance document must indicate what namespace(s) the elements belong to –So that the document can be validated –3 ways to indicate this controlled by elementFormDefault attribute in Schema file <xs:schema targetNamespace=" xmlns:res=" xmlns:xs=" elementFormDefault="qualified"> 1.Default namespace xmlns tags a whole section Advantages: Great for simple ns use Disadvantages: Can be confusing for authors when drawing on multiple schema 2.Namespace prefixes Invidually tag elements Advantages: Visually explicit about ns membership Can mix in elements from different ns with the same name. Disadvantages: Error-prone, ugly when drawing multiple schema 3.Unqualified: tag (global) root element Advantages: Single prefix tag needed at the top of the document; no other tags needed Good for when using multiple schemas together Least error prone Makes XPaths simpler Disadvantage: Cant have 2 elements from different ns w/same name elementFormDefault="qualified"elementFormDefault="unqualified" <resource xmlns=" … Archive <vr:resource xmlns:vr=" xmlns:cv=" … <vr:resource xmlns:vr=" … IVOA VOResource uses this technique

7 September 2005NVO Summer School Aspen31 XPath What it is: –A W3C standard syntax for pointing to elements, attributes, and/or their values in an XML file Why you might care: –XPath is used in two other important XML technologies: XQuery and XSL –XPath is used in ADQL to query a registry via the standard Registry Interface What youll get from this session: –Ability to form simple XPath queries

7 September 2005NVO Summer School Aspen32 Can you tell me how to get to Sesame Street? An XPath is a set of directions from one point in an XML document to another sunny Begin at the start of the document

7 September 2005NVO Summer School Aspen33 Can you tell me how to get to Sesame Street? An XPath is a set of directions from one point in an XML document to another sunny Go to NewYork

7 September 2005NVO Summer School Aspen34 Can you tell me how to get to Sesame Street? An XPath is a set of directions from one point in an XML document to another sunny Find the Borough named Brooklyn

7 September 2005NVO Summer School Aspen35 Can you tell me how to get to Sesame Street? An XPath is a set of directions from one point in an XML document to another sunny Go to the 3 rd light

7 September 2005NVO Summer School Aspen36 Can you tell me how to get to Sesame Street? An XPath is a set of directions from one point in an XML document to another sunny And theres SesameStreet

7 September 2005NVO Summer School Aspen37 XPath syntax XPath fields (between the /s) –Each represents a descent in the XML hierarchy // means drop any number of levels –Points to an XML node element name or, if preceeded with an attribute name –Other useful node-matching symbols * = wildcard (any name). = current node.. = parent node Context node = starting point –If it does not start with a /, XPath is relative to a context-specific starting is an XPath relative to /NewYork/Burough Predicates: [ ] –Read […] as where … –XPaths inside resolve to string value inside element/attribute pointed to –Operators: = != = and or –Many Useful Functions: contains( string, string ), position(), count(), last(), local-name() –[3] is short-hand for [position()=3]

7 September 2005NVO Summer School Aspen38 XPath as a Query An XPath returns matched XML nodes On… sunny Returns… sunny

7 September 2005NVO Summer School Aspen39 XPath as a Query An XPath returns matched XML nodes /NewYork/Burough/light On… sunny Returns… sunny

7 September 2005NVO Summer School Aspen40 XPath as a Query An XPath returns matched XML nodes /NewYork/Burough/light/SesameStreet/weather On… sunny Returns… sunny

7 September 2005NVO Summer School Aspen41 XPath as a Query An XPath returns matched XML nodes string(/NewYork/Burough/light/SesameStreet/weather) On… sunny Returns… sunny

7 September 2005NVO Summer School Aspen42 XPath as a Query An XPath returns matched XML nodes /NewYork/Burough/light/SesameStreet[weather='sunny'] On… sunny Returns… sunny weather was automatically converted to a string before comparison operator was applied.

7 September 2005NVO Summer School Aspen43 XPath as a Query An XPath returns matched XML nodes –If path is ambiguous, all matching nodes are returned –If path does not resolve to an existing node, the empty set is returned –Predicates, [ … ], provide constraints In some contexts, XPath is automatically converted to string value inside the matched element or attribute. Examples querying a set of VOResource documents /Resource[contains(content/description, 'cluster')] –Return all resource elements where the description contains the word cluster /Resource[facility] –Return all resources that have a facility element –Return the interface URLs of all ConeSearch services –Return all data collections that purport to have data distributed overall

7 September 2005NVO Summer School Aspen44 XPath as a Query An XPath returns matched XML nodes –If path is ambiguous, all matching nodes are returned –If path does not resolve to an existing node, the empty set is returned –Predicates, [ … ], provide constraints In some contexts, XPath is automatically converted to string value inside the matched element or attribute. Examples querying a set of VOResource documents /Resource[contains(content/description, 'cluster')] –Return all resource elements where the description contains the word cluster /Resource[facility] –Return all resources that have a facility element –Return the interface URLs of all ConeSearch services –Return all data collections that purport to have data distributed overall

7 September 2005NVO Summer School Aspen45 XQuery (a.k.a. XML Query) What it is: –A W3C standard for querying XML documents An analogue to SQL for tables Why you might care: –It is one of the supported query languages in the standard VO Registry Interface. –It can handle certain complex registry queries that ADQL cannot What youll get from this session: –Ability to query XML documents by modifying existing an XQuery

7 September 2005NVO Summer School Aspen46 XQuery: an analogy to SQL SQL queries tables –Result of an SQL statement is a table –Columns of result table controlled by the SELECT clause –Rows controlled by the WHERE clause XQuery queries XML documents –Result of an XQuery is an XML document –The form of the XML document is set by the return clause –The contents of the result is controlled by the for, let, and where clauses

7 September 2005NVO Summer School Aspen47 XQuery syntax: think FLWOR XQuery supports several types of expressions that can return XML results –XPath, Constructors, … –FLWOR = for let where orderby return FLWOR clauses –for/let clause selects data from source XML documents

7 September 2005NVO Summer School Aspen48 XQuery syntax: think FLWOR Searching for Cone Search services suitable for getting data about galaxy clusters To be used with the Carnivore Registry declare namespace vr= " declare namespace vs= " for $vr in where contains($vr//description, "quasar") return {string(title)} {string($vr/capability/interface/accessURL)}

7 September 2005NVO Summer School Aspen49 XQuery syntax: think FLWOR Searching for Cone Search services suitable for getting data about galaxy clusters To be used with the Carnivore Registry Declare namespace prefixes to use in query declare namespace vr= " declare namespace vs= " for $vr in where contains($vr//description, "quasar") return {string(title)} {string($vr/capability/interface/accessURL)}

7 September 2005NVO Summer School Aspen50 XQuery syntax: think FLWOR for clause sets up a loop around matching occurrences –XPath both selects the Resource element node to put into the variable and constrains which Resources are included let clause (not used here) can also set variables. –Used to join across documents, self-joins –If $vr is used in the variable definition, the new value would be different in each pass of the loop. Loop over all ConeSearch resources declare namespace vr= " declare namespace vs= " for $vr in where contains($vr//description, "quasar") return {string(title)} {string($vr/capability/interface/accessURL)} Declare namespace prefixes to use in query

7 September 2005NVO Summer School Aspen51 XQuery syntax: think FLWOR where clause further restricts the output –Optional, often dont need it: for $vr in and contains($vr//vr:description, "quasar")] Restrict output to ConeSearch services about quasars declare namespace vr= " declare namespace vs= " for $vr in where contains($vr//description, "quasar") return {string(title)} {string($vr/capability/interface/accessURL)} Loop over all ConeSearch resources Declare namespace prefixes to use in query

7 September 2005NVO Summer School Aspen52 XQuery syntax: think FLWOR return clause sets the output template –{ } used to denote non-literal output –Applied to each value of $vr XQuery supports several other expression types not shown here –Conditionals, function definition, etc. –Many more predefined funtions XQuery: a full XML processing language Loop over all ConeSearch resources Extract and display Desired information Restrict output to ConeSearch services about quasars Declare namespace prefixes to use in query declare namespace vr= " declare namespace vs= " for $vr in where contains($vr//description, "quasar") return {string(title)} {string($vr/capability/interface/accessURL)}

7 September 2005NVO Summer School Aspen53 XSL – XML Stylesheet Language What it is –A language for describing the transformation of XML data from one form to another XML -> HTML XML -> XML XML -> Plain text Why you might care –XSL can be used to create human readable renderings of XML data from the VO –XSL is used by the Java Skynode toolkit for converting ADQL to local SQL What youll get from this session: –Ability to modify XML transformations via simple changes to a stylesheet

7 September 2005NVO Summer School Aspen54 XML Stylesheet Language An XML document that describes a transformation Contains a list of templates –Each describes the transformation for one type of node (e.g. an element with a particular name) –Node is identified by an XPath Relative to current context node –Usually one template for /, the root of the document –A template can call other templates XSL provides a number of programming structures –Conditionals, looping, user-defined functions, built-in functions, extensibilty –Variables are immutable! XSLT = XSL Transformation

7 September 2005NVO Summer School Aspen55 A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text <xsl:stylesheet xmlns=" xmlns:vr=" xmlns:vs=" xmlns:xsl=" xmlns:xsi=" version="1.0"> Resource Description Record

7 September 2005NVO Summer School Aspen56 A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text Define prefixes for all namespaces well be using <xsl:stylesheet xmlns=" xmlns:vr=" xmlns:vs=" xmlns:xsl=" xmlns:xsi=" version="1.0"> Resource Description Record

7 September 2005NVO Summer School Aspen57 A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text Three output types –xml, html, text Define prefixes for all namespaces well be using Our output format will be plain text <xsl:stylesheet xmlns=" xmlns:vr=" xmlns:vs=" xmlns:xsl=" xmlns:xsi=" version="1.0"> Resource Description Record

7 September 2005NVO Summer School Aspen58 A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text When raw text appears, XSLT engine will preserve spacing (like carriage returns) around text Resource is the root of our data document Define prefixes for all namespaces well be using Our output format will be plain text Our root document template sets up the output document and calls next template <xsl:stylesheet xmlns=" xmlns:vr=" xmlns:vs=" xmlns:xsl=" xmlns:xsi=" version="1.0"> Resource Description Record

7 September 2005NVO Summer School Aspen59 A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text When a template runs, it changes the context node to the node matched by the template Subsequent XPaths within template are relative to that context node ( ) IVOA Identifier: Target Communities:, Resource template

7 September 2005NVO Summer School Aspen60 A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text text tags can be used to take explicit control of spacing Resource template ( ) IVOA Identifier: Target Communities:,

7 September 2005NVO Summer School Aspen61 A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text our XPaths point to elements –Relative to vr:Resource ! value-of will convert it to a string text tags can be used to take explicit control of spacing value-of will print the string values of nodes Resource template ( ) IVOA Identifier: Target Communities:,

7 September 2005NVO Summer School Aspen62 A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text text tags can be used to take explicit control of spacing value-of will print the string values of nodes Pass control to other templates Resource template ( ) IVOA Identifier: Target Communities:,

7 September 2005NVO Summer School Aspen63 Normally, apply-templates will automatically loop over multiple occurances Here, we need to insert commas for-each also changes the context node A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text text tags can be used to take explicit control of spacing value-of will print the string values of nodes Pass control to other templates Resource template Loop over all occurances of contentLevel ( ) IVOA Identifier: Target Communities:,

7 September 2005NVO Summer School Aspen64 Use choose/when for if-then-else blocks A tour through a stylesheet xmltech-VOResource.xsl to transform xmltech-adil.xml into plain text text tags can be used to take explicit control of spacing value-of will print the string values of nodes Pass control to other templates Resource template Loop over all occurances of contentLevel If block ( ) IVOA Identifier: Target Communities:,

7 September 2005NVO Summer School Aspen65 XSL for metadata Transformation is a powerful paradigm for metadata processing –Consider all uses of metadata as a transformation to another form… User display An SQL statement A workflow script Compile-able code –XSL stylesheet somewhere between configuration file and script Rapid prototyping and adaptation xsl:import : ability to extend & override other stylesheets