More XML XML schema, XPATH, XSLT - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

More XML XML schema, XPATH, XSLT

Description:

Match attribute value is xpath expression. Non-xsl namespace elements are literals. ... attributes. Nesting structure (parent/child rela.) Sibling sequence ... – PowerPoint PPT presentation

Number of Views:158
Avg rating:3.0/5.0
Slides: 33
Provided by: carll8
Category:
Tags: xml | xpath | xslt | attribute | more | schema

less

Transcript and Presenter's Notes

Title: More XML XML schema, XPATH, XSLT


1
More XMLXML schema, XPATH, XSLT
  • CS 431 20040225
  • Carl Lagoze Cornell University

2
A little context
DTD Tag Sets
3
XPath
  • Language for addressing parts of an XML document
  • XSLT
  • Xpointer
  • Tree model similar to DOM
  • W3C Recommendation (1999)
  • http//www.w3.org/TR/xpath

4
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
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 axisnode-testpredicate
  • Examples
  • childBookposition() lt 3 first three ltBookgt
    child elements of context
  • childBook/attributecolor color attributes
    of ltBookgt child elements of context

9
Abbreviations
  • Child axis is default
  • childBook ? Book
  • Attribute axis ? _at_
  • Bookposition() 1/_at_color
  • . (self), .. (parent), //
    (descendent-or-self)
  • position() n ? n
  • Example
  • Book2/_at_color

10
XML Transformations (XSLT)
  • Origins separate rendering from data
  • Roots in CSS
  • W3C Recommendation
  • http//www.w3.org/TR/xslt
  • 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
XSLT Processing Model
XSLT
serialize
parse
Input XMLdoc
Parsedtree
Xformedtree
Outputdoc(xml, html, etc)
13
XSLT engine
XML input
XSLT Engine (SAXON)
Output Document (xml, html, )
XSLT program
14
Stylesheet Document or Program
  • XML document rooted in ltstylesheetgt 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
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xslt/simple.xsl
  • XML base file
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xslt/simple.xml

17
XSLT Recursive Programming Style
  • Document driven, template matching
  • Conflict resolution rules
  • Mode setting
  • ltxslapply-templates modethisgt
  • ltxsltemplate matchfoo modethisgt
  • ltxsltemplate matchfoo modethatgt
  • Context setting
  • ltxslapply-templates select//bargt

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
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xslt/foreach.xsl
  • XML base file
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xslt/foreach.xml

20
Call-template programming example
  • XML base file
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xslt/call.xml
  • XSLT file
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xslt/call.xsl

21
Result Tree Creation
  • Literals any element not in xsl namespace
  • ltxsltextgt - content directly to output
  • ltxslvalue-ofgt - expression processing
  • ltxslcopygt and ltxslcopyofgt - Copy current node
    or selected nodes into result tree
  • ltxslelementgt - instantiate an element
  • ltxslattributegt - instantiate an attribute

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

23
Resources
  • XSLT WROX Press
  • ISBN 1-861005-06-7
  • W3C XSLT Page
  • http//www.w3.org/Style/XSL/
  • TopXML XSL Tutorial
  • http//www.vbxml.com/xsl/tutorials/intro/default.a
    sp

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
Simple Value Types
  • Restriction on type of content
  • Syntax
  • ltxselement namexxx typeyyy/gt
  • Examples
  • ltxselement namelastname typexsstring/gt
  • ltxselement nameage typexsnumber/gt
  • ltxselement nameage typexsdate/gt

27
Facets
  • Restrictions on values within type context
  • Examples

28
Simple Example
  • Memo Schema
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xmlschema/memo.xsd
  • Memo Instance Document
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xmlschema/memo.xml

29
Type extension/restriction
30
Type Reuse
31
Type Reuse Example
  • Base Type Definition
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xmlschema/address.xsd
  • Type Use
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xmlschema/person.xsd
  • Instance Document
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xmlschema/person.xml

32
DTD XML Schema Equivalence
  • DTD Example
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xmlschema/channel.dtd
  • Equivalent Schema
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xmlschema/channel.xsd
  • Instance Document
  • http//www.cs.cornell.edu/Courses/cs502/2002SP/Dem
    os/xmlschema/channel.xml
Write a Comment
User Comments (0)
About PowerShow.com