Presentation is loading. Please wait.

Presentation is loading. Please wait.

Comparing XSLT and XQuery Michael Kay XTech 2005.

Similar presentations


Presentation on theme: "Comparing XSLT and XQuery Michael Kay XTech 2005."— Presentation transcript:

1 Comparing XSLT and XQuery Michael Kay XTech 2005

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

3 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 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 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 6 XQuery FLWOR expressions Relational style of query Convenient for data manipulation Optimization theory well-understood Appeal to SQL users No functionality that can’t be expressed in XSLT

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

8 8 Use of XML Syntax XSLT uses XML syntax, XQuery doesn’t 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 9 XSLT Example 1 remove all @NOTE attributes <xsl:stylesheet version=“2.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform ">

10 10 XQuery Example 1 remove all @NOTE attributes xquery version 1.0; declare function local:copy($node as element()) { element {node-name($node)} { @* except @NOTE, for $c in child::node return typeswitch($c) case $e as element() return local:copy($a) case $t as text() return $t case $c as comment() return $c case $p as processing-instruction return $p } }; local:copy(/*)

11 11 XQuery Example 2 join two tables xquery version 1.0; { 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/@person = $p/@id return $t return {count ($a)} } XMark Q8

12 12 XSLT Example 2 join two tables <xsl:variable name="a" select="/site/closed_auctions/closed_auction [buyer/@person = current()/@id]"/> XMark Q8

13 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 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 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 = 3 return $x spot the error!

16 16 Performance and Optimization XMark Q8 (shown earlier) –XQuery version –XSLT version Database sizes –1Mb –4Mb –10Mb

17 17 XMark Q8 results (msecs) 1Mb 1503 160 33 90 Xalan xt MSXML Saxon 8.4 XSLT XQuery Saxon 8.4 Qizx Galax 136 351 1870 4Mb 11006 2253 519 1340 1575 711 6672 10Mb 65855 16414 4248 11126 11947 1813 16625 O(n 2 ) O(n)

18 18 Two can play at that game! Xalan xt MSXML Saxon 8.5 1Mb 1503 160 33 27 XSLT XQuery Saxon 8.5 Qizx Galax 16 351 1870 4Mb 11006 2253 519 26 16 711 6672 10Mb 65855 16414 4248 45 31 1813 16625 O(n 2 ) O(n) caveat: this is one query only!

19 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


Download ppt "Comparing XSLT and XQuery Michael Kay XTech 2005."

Similar presentations


Ads by Google