Presentation is loading. Please wait.

Presentation is loading. Please wait.

More XML XML schema, XPATH, XSLT

Similar presentations


Presentation on theme: "More XML XML schema, XPATH, XSLT"— Presentation transcript:

1 More XML XML schema, XPATH, XSLT
CS 431 – Carl Lagoze – Cornell University

2 Distributed, interlinked
A little context RDF Semantic Relationships DAML+OIL Concept Building Semantic Web Traditional Library Central control Uniform expertise Traditional Web Distributed, interlinked Viewable Documents Xpath Data Decomposition XSLT Transformation Schema Type Definition Namespaces Concept Integration DTD Tag Sets XML Markup Syntax URIs Name Convention HTTP Access Method

3 Language for addressing parts of an XML document
XPath Language for addressing parts of an XML document XSLT Xpointer Tree model similar to DOM W3C Recommendation (1999)

4 Location Steps – selection from context node
Xpath Concepts Context Node current node in XML document that is basis of path evaluation Default to root Location Steps – selection from context node Axis – sub-tree(s) selection from context node Node Test – select specific elements or node type(s) Predicates – predicate for filtering after axis and node tests

5 Axis child: all children of context descendent: all children, grandchildren, … parent: ancestor

6 Node Test Element name: e.g. “Book” Wildcard: * Type(): where type is “node”, “text”, etc.

7 Boolean and comparative operators Types
Predicate Boolean and comparative operators Types Numbers Strings node-sets Functions Examples boolean starts-with(string, string) number count(node-set)

8 Combining all into a location set specification
Syntax: axis::node-test[predicate] Examples: child::Book[position() <= 3] – first three <Book> child elements of context child::Book/attribute::color – “color” attributes of <Book> child elements of context

9 “.” (self), “..” (parent), “//” (descendent-or-self)
Abbreviations Child axis is default child::Book  Book Attribute axis Book[position() = “.” (self), “..” (parent), “//” (descendent-or-self) position() = n  n Example

10 XML Transformations (XSLT)
Origins: separate rendering from data Roots in CSS W3C Recommendation Generalized notion of transformation for: Multiple renderings Structural transformation between different languages Dynamic documents XSLT – rule-based (declarative) language for transformations

11 XSLT Capabilities Generate constant text Filter out content Change tree ordering Duplicate nodes Sort nodes Any computational task (XSLT is “turing complete”)

12 Output doc (xml, html, etc)
XSLT Processing Model parse XSLT serialize Input XML doc Parsed tree Xformed tree Output doc (xml, html, etc)

13 XSLT “engine” XSLT Engine (SAXON) XML input Output Document
(xml, html, …) XSLT “program”

14 Stylesheet Document or Program
XML document rooted in <stylesheet> element Body is set of templates Xpath expression specifies elements in source tree Body of template specifies contribution of source elements to result tree Not sequential execution

15 Template Form Elements from xsl namespace are transform instructions
Match attribute value is xpath expression Non-xsl namespace elements are literals.

16 A simple example XSLT file XML base file
XML base file

17 XSLT Recursive Programming Style
Document driven, template matching Conflict resolution rules Mode setting <xsl:apply-templates mode=“this”> <xsl:template match=“foo” mode=“this”> <xsl:template match=“foo” mode=“that”> Context setting <xsl:apply-templates select=“//bar”>

18 XSLT Procedural Programming
Sequential programming style Basics for-each – loop through a set of elements call-template – like a standard procedure call

19 For-each programming example
XSLT file XML base file

20 Call-template programming example
XML base file XSLT file

21 Result Tree Creation Literals – any element not in xsl namespace <xsl:text> - content directly to output <xsl:value-of> - expression processing <xsl:copy> and <xsl:copyof> - Copy current node or selected nodes into result tree <xsl:element> - instantiate an element <xsl:attribute> - instantiate an attribute

22 Various other programming constructs
Conditionals Variables (declaration and use) Some type conversion Sorting

23 Resources XSLT – WROX Press W3C XSLT Page TopXML XSL Tutorial
ISBN W3C XSLT Page TopXML XSL Tutorial

24 XML Schema Define… elements attributes Nesting structure (parent/child rela.) Sibling sequence Sibling cardinality Presence or absence of text values Element and attribute data types Element and attribute default values

25 Simple vs. Complex Values
Element with complex value contains other elements (has children) Element with simple value does not have children (e.g. text).

26 Restriction on type of content Syntax
Simple Value Types Restriction on type of content Syntax <xs:element name=“xxx” type=“yyy”/> Examples <xs:element name=“lastname” type=“xs:string”/> <xs:element name=“age” type=“xs:number”/> <xs:element name=“age” type=“xs:date”/>

27 Facets Restrictions on values within type context Examples

28 Memo Instance Document
Simple Example Memo Schema Memo Instance Document

29 Type extension/restriction

30 Type Reuse

31 Type Reuse Example Base Type Definition Type Use Instance Document
Type Use Instance Document

32 DTD & XML Schema Equivalence
DTD Example Equivalent Schema Instance Document


Download ppt "More XML XML schema, XPATH, XSLT"

Similar presentations


Ads by Google