Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
1XSLT
CPS 216
Advanced Database Systems
2
Announcements (March 16)
™ Graded Midterm, sample solution, and graded Homework 
#2 will be handed out on Thursday
™ Homework #3 out on Thursday
™ Course project milestone 2 due in two weeks
™ Reading assignment for next week
ƒ McHugh and Widom, VLDB 1999
ƒ Halverson et al., VLDB 2003
ƒ Both due next Monday
™ Talk by Ashraf Aboulnaga
ƒ On-line Statistics for Database Query Optimization
ƒ Thursday 11:30am-12:30pm, D106
3
XSLT
™W3C recommendation
™XML-to-XML rule-based transformation language
™An XSLT program is an XML document itself
™Used most frequently as a stylesheet language
XSLT processor
XSLT program
Input XML Output XML
Actually, output does not need to be in XML in general
4
XSLT program
™An XSLT program is an XML document containing
ƒ Elements in the  namespace
ƒ Elements in user namespace
™The result of evaluating an XSLT program on an 
input XML document =
the XSLT document where each  element 
has been replaced with the result of its evaluation
™Uses XPath as a sub-language
5
XSLT elements
™ Element describing transformation rules
ƒ 
™ Elements describing rule execution control
ƒ 
ƒ 
™ Elements describing instructions
ƒ , , , etc.
™ Elements generating output
ƒ , , , , etc.
6
XSLT example
™ Find titles of books authored by “Abiteboul”








™Not quite; we will see why later
Standard header of an XSLT document
27






™  is the basic XSLT construct 
describing a transformation rule
ƒ match_expr is an XPath-like expression specifying which nodes this 
rule applies to
™  evaluates xpath_expr
within the context of the node matching the template, and converts 
the result node-set to a string
™  and  simply get copied to the output 
for each node match
8
Template in action





™ Example XML fragment

Foundations of Databases
Abiteboul
Hull
Vianu
Addison Wesley
1995
A First Course in Databases Ullman Widom Prentice-Hall 2002
Template applies Foundations of Databases Template does not apply; default behavior is to process the node recursively and print out all text nodes A First Course in Databases Ullman Widom Prentice-Hall 2002 … … 9 Removing the extra output ™Add the following template: ™This template matches all text and attributes ™XPath features ƒ text() is a node test that matches any text node ƒ @* matches any attribute ƒ | means “or” in XPath ™Body of the rule is empty, so all text and attributes become empty string ƒ This rule effectively filters out things not matched by the other rule 10 ™ Again, find titles of books authored by “Abiteboul”; but make the output look like … … … … ™ A more general method … … … … body adds an attributed named attr with value body to the parent element in the output 11 ™ Another slightly different example: return (entire) books authored by “Abiteboul” ™ copies the entire contents (including tag structures) of the node-set returned by xpath_expr to the output 12 Formatting XML into HTML ™ Example templates to ƒ Render a book title in italics in HTML ƒ Render the authors as a comma-separated list 1]”> , ™ allows precise control of white space in output 313 ™ Example: generate a table of contents ƒ Display books in an HTML unordered list ƒ For each book, first display its title, and then display its sections in an HTML ordered list ƒ For each section, first display its title, and then display its subsections in an HTML ordered list
  • (Continue on next slide) applies templates recursively to the node-set returned by xpath_expr 14 Example continued
  • Bibliography
    ™ One problem remains ƒ Even if a book or a section has no sections, we will still generate an empty
      element 15 ™A fix using : replace
      with
      ™The body of is processed only if xpath_cond evaluates to true 16 White space control ™ White space is everywhere in XML … … ↵ tt↵ ttttFoundations of Databases↵ tt… … ƒ “↵tt” goes into a text node ƒ “↵ttttFoundations of Databases↵tt” goes into another text node ™ Specify to remove text nodes (under any element) containing only white space ™ To strip leading and trailing white space and replace any sequence of white space characters by a single space, specify 17 ™ body ƒ Process body for each node in the node-set returned by xpath_expr ƒ Processing context changes to the node being processed ™ Another way to render authors as a comma-separated list … … 1”>, … …
      18 Named templates with parameters ™Define a generic template for rendering a list of things as a comma-separated list ƒ Cannot use match because we do not know in advance the things to render , 419 Calling templates & passing parameters ™ Use the generic template :
      ™ evaluates xpath_expr and passes its result as the value of the parameter para_name ™ invokes the named template without changing the context 20 XSLT summary ™Used often as a stylesheet language, but can be considered a query language too ƒ Very expressive, with full recursion • Cannot be replaced by XQuery ƒ Easily non-terminating, difficult to optimize • Cannot replace XQuery ™ So many features, so little time! ☺ 21 Review ™ XML: tree (or graph)-structured data ™ DTD: simple schema for XML ƒ Well-formed XML: syntactically correct ƒ Valid XML: well-formed and conforms to a DTD ™ XPath: path expression language for XML ƒ An XPath expression selects a list of nodes in an XML document ƒ Used in other languages ™ XQuery: SQL-like query language for XML ƒ FLWOR expression, quantified expression, aggregation, etc. ™ XSLT: stylesheet language for XML, in XML ƒ Transforms input XML by applying template rules recursively on the structure of input XML 22 XML API’s ™ SAX (Simple API for XML) ƒ Started out as a Java API, but now exists for other languages too ƒ Streaming input; callbacks for events (start/end of document and elements, chunk of characters, etc.) ™ DOM (Document Object Model) ƒ Language-neutral API with implementations in Java, C++, etc. ƒ Converts input into a main-memory tree; supports tree traversal, construction, and in-place modification ™ JAXB (Java Architecture for XML Binding) ƒ XML Schema to Java objects ) Not covered further in lecture, but SAX and DOM will be covered in more detail in recitation