Presentation is loading. Please wait.

Presentation is loading. Please wait.

More XML XML schema, XPATH, XSLT CS 431 – February 21, 2005 Carl Lagoze – Cornell University acknowledgements to

Similar presentations


Presentation on theme: "More XML XML schema, XPATH, XSLT CS 431 – February 21, 2005 Carl Lagoze – Cornell University acknowledgements to"— Presentation transcript:

1 More XML XML schema, XPATH, XSLT CS 431 – February 21, 2005 Carl Lagoze – Cornell University acknowledgements to http://www.w3schools.com/schema/default.asp

2 xHTML HTML “expressed” in XML Corrects defects in HTML –All tags closed –Proper nesting –Case sensitive (all tags lower case) –Strict well-formedness Defined by a DTD –

3 xHTML (cont.) All new HTML SHOULD be xHTML W3C validator –http://validator.w3.orghttp://validator.w3.org Tidy –http://sourceforge.net/projects/jtidyhttp://sourceforge.net/projects/jtidy

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

5 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

6 Structure of a schema well-formed xml document elements are in schema namespace root is element

7 Instantiation of a schema Note namespaces!!

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

9 Simple Value Types Restriction on type of content Syntax – Examples –

10 Facets Restrictions on values within type context Examples

11 String types and patterns

12 Simple Example Memo Schema –http://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/memo.xsdhttp://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/memo.xsd Instance Document –http://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/memo.xmlhttp://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/memo.xml

13 Complex Types Type definition defines elements nesting

14 Controls on complex types sequence – specific order all – any order choice – only one cardinality – minOccurs, maxOccurs

15 Complex Type Extension Add values to sequence

16 Mixed Content

17 Declaring attributes Define type –xs:string –xs:decimal –xs:integer –xs:boolean –xs:date –xs:time Define optional or required

18 Use of attributes Always a complex type

19 Type Reuse

20 Type Reuse Example Address schema –http://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/address.xsdhttp://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/address.xsd Person schema –http://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/person.xsdhttp://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/person.xsd Instance document –http://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/person.xmlhttp://www.cs.cornell.edu/lagoze/courses/CS431/2005s p/Examples/Lecture9/person.xml

21 XPath Language for addressing parts of an XML document –XSLT –Xpointer Tree model similar to DOM W3C Recommendation (1999) –http://www.w3.org/TR/xpathhttp://www.w3.org/TR/xpath

22 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

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

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

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

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

27 Abbreviations Child axis is default –child::Book  Book Attribute axis  @ –Book[position() = 1]/@color “.” (self), “..” (parent), “//” (descendent-or-self) position() = n  n Example –Book[2]/@color

28 XML Transformations (XSLT) Origins: separate rendering from data –Roots in CSS W3C Recommendation –http://www.w3.org/TR/xslthttp://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

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

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

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

32 Stylesheet Document or Program XML document rooted in 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

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

34 A simple example XML base file –http://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/simple.xmlhttp://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/simple.xml XSLT file –http://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/simple.xslhttp://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/simple.xsl

35 XSLT Recursive Programming Style Document driven, template matching –Conflict resolution rules –Mode setting –Context setting

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

37 For-each programming example XML base file –http://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/foreach.xmlhttp://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/foreach.xml XSLT file –http://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/foreach.xslhttp://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/foreach.xsl

38 Call-template programming example XML base file –http://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/call.xmlhttp://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/call.xml XSLT file –http://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/call.xslhttp://www.cs.cornell.edu/Courses/cs502/2002SP/Demo s/xslt/call.xsl

39 Result Tree Creation Literals – any element not in xsl namespace - content directly to output - expression processing and - Copy current node or selected nodes into result tree - instantiate an element - instantiate an attribute

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

41 Resources XSLT – WROX Press –ISBN 1-861005-06-71-861005-06-7 W3C XSLT Page –http://www.w3.org/Style/XSL/http://www.w3.org/Style/XSL/ Arbortext XSL Tutorial –http://www.nwalsh.com/docs/tutorials/xsl/


Download ppt "More XML XML schema, XPATH, XSLT CS 431 – February 21, 2005 Carl Lagoze – Cornell University acknowledgements to"

Similar presentations


Ads by Google