Comparing XSLT and XQuery - PowerPoint PPT Presentation

Loading...

PPT – Comparing XSLT and XQuery PowerPoint presentation | free to download - id: 2371cc-N2NjZ



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Comparing XSLT and XQuery

Description:

Same function library. Similar mechanisms for defining functions ... XSLT Example 2. join two tables ... less trouble with set algebra. tend to write everything ... – PowerPoint PPT presentation

Number of Views:148
Avg rating:3.0/5.0
Slides: 20
Provided by: sof52
Learn more at: http://www.mscs.mu.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Comparing XSLT and XQuery


1
Comparing XSLT and XQuery
  • Michael Kay
  • XTech 2005

2
About me
  • Database background
  • Started using XML in 1998 for content management
    applications
  • Author of XSLT Programmers Reference
  • Developer of Saxon XSLT processor
  • Member of W3C XSL and XQuery Working Groups
  • Founded SAXONICA March 2004

3
Comparison Points
  • 1 Functionality
  • features in the language
  • 2 Aesthetics
  • likes and dislikes
  • learning barriers
  • usability, actual and perceived
  • 3 Implementations
  • maturity, conformance
  • performance
  • market focus

4
Functional Overlap
  • Same data model and type system
  • XPath as common subset
  • Same function library
  • Similar mechanisms for defining functions
  • Similar mechanisms for constructing elements and
    attributes
  • Both declarative languages

5
XSLT 2.0 also has...
  • Template rules
  • Formatting (dates, numbers)
  • More regular expression handling
  • Multiple output documents
  • Plain text input and output
  • Refinement (import precedence)
  • Keys

6
XQuery FLWOR expressions
  • Relational style of query
  • Convenient for data manipulation
  • Optimization theory well-understood
  • Appeal to SQL users
  • No functionality that cant be expressed in XSLT

7
Consequences...
  • XSLT is stronger on
  • rendition
  • up-conversion
  • documents
  • XQuery is stronger on
  • optimization
  • structured data

8
Use of XML Syntax
  • XSLT uses XML syntax, XQuery doesnt
  • Advantages
  • stylesheets are documents, they can be edited,
    stored, transformed, validated, embedded,
    transcoded
  • XML syntax is extensible and robust
  • Disadvantages
  • XML is ugly and verbose
  • Easier to embed XQuery in Java or C

9
XSLT Example 1remove all _at_NOTE attributes
ltxslstylesheet version2.0"
xmlnsxsl"http//www.w3.org/1999/XSL/Transform"gt
ltxsltemplate match""gt ltxslcopygt
ltxslcopy-of select"_at_ except _at_NOTE"/gt
ltxslapply-templates/gt lt/xslcopygt lt/xsltemplat
egt lt/xslstylesheetgt
10
XQuery Example 1remove all _at_NOTE attributes
xquery version 1.0 declare function
localcopy(node as element()) element
node-name(node) _at_ except _at_NOTE, for
c in childnode return typeswitch(c)
case e as element() return localcopy(a)
case t as text() return t case c as
comment() return c case p as
processing-instruction return p
localcopy(/)
11
XQuery Example 2join two tables
xquery version 1.0 ltresultsgt for p in doc
("auction.xml")/site/people/person let a
for t in doc("auction.xml")
/site/closed_auctions/closed_auction
where t/buyer/_at_person p/_at_id
return t return ltitem person"p/name"gt
count (a) lt/itemgt lt/resultsgt
XMark Q8
12
XSLT Example 2join two tables
ltresult xslversion"1.0" xmlnsxsl"http//www.w3
.org/1999/XSL/Transform"gt ltxslfor-each
select"/site/people/person"gt ltxslvariable
name"a" select"/site/closed_auctions/clo
sed_auction
buyer/_at_person current()/_at_id"/gt ltitem
person"name"gt ltxslvalue-of
select"count(a)"/gt lt/itemgt
lt/xslfor-eachgt lt/resultgt
XMark Q8
13
XSLT Learning Barriers
  • XML
  • encoding, entities, whitespace, namespaces
  • Declarative programming
  • variables, recursion, paths, grouping
  • Data model
  • nodes not angle brackets
  • Rule-based programming
  • templates

14
XQuery Learning Barriers
  • XML
  • encoding, entities, whitespace, namespaces
  • Declarative programming
  • variables, recursion, paths, grouping
  • Data model
  • nodes not angle brackets
  • Rule-based programming
  • templates

15
Learning Barriers?
  • It depends where you are coming from!
  • Many XQuery users come from SQL
  • less trouble with set algebra
  • tend to write everything as a FLWOR expression

let x //item where x/code 3return x
spot the error!
16
Performance and Optimization
  • XMark Q8 (shown earlier)
  • XQuery version
  • XSLT version
  • Database sizes
  • 1Mb
  • 4Mb
  • 10Mb

17
XMark Q8 results (msecs)
18
Two can play at that game!
1Mb
XSLT
4Mb
10Mb
Xalan
1503
11006
65855
O(n2)
xt
160
2253
16414
MSXML
33
519
4248
Saxon 8.5
27
26
45
O(n)
XQuery
Saxon 8.5
16
16
31
Qizx
351
711
1813
Galax
1870
6672
16625
caveat this is one query only!
19
Conclusions
  • Two languages with a high degree of functional
    overlap
  • Different aesthetics, but similar learning
    challenges
  • XSLT has richer functionality especially for
    document rendering
  • XQuery products are more likely to be optimized
    for large amounts of structured data
About PowerShow.com