Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 Advanced Database SystemsCOSC282 G OWRI S HANKAR D ARA T EAM M EMBERS D ARREL M AZZARI A LBIN L AGA A DITYA T.

Similar presentations


Presentation on theme: "1 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 Advanced Database SystemsCOSC282 G OWRI S HANKAR D ARA T EAM M EMBERS D ARREL M AZZARI A LBIN L AGA A DITYA T."— Presentation transcript:

1 1 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 Advanced Database SystemsCOSC282 G OWRI S HANKAR D ARA T EAM M EMBERS D ARREL M AZZARI A LBIN L AGA A DITYA T RIPURANENI

2 2 OVERVIEW INTRODUCTION SYSTEM ARCHITECTURE APPROACH SPECIFIC EXAMPLES CONCLUSION T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

3 3 WHY USE XSLT & XQUERY 1.) Overcome most technical heterogeneities of diverse databases by using W3C recommendations XPath and XQuery, and other techniques like XSLT and SOAP (Simple Object Access Protocol) 2.) XML databases can be transmitted and stored as text files with schema information transported using XML schemas or Document Type Definition files. 3) XSLT is written independently of any programming language and it can be executed by a program written in most modern programming languages (Jovanovic, et. al., 2005).

4 4 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 Definitions XML (eXtensible Markup Language) is a standard for creating markup languages which describe the structure of data. XSLT (eXtensible Stylesheet Language Transformations) is the language used in XSL style sheets to transform XML documents into other XML documents, on the basis of a set of well-defined rules.

5 5 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 Definitions Xquery is a programming language that provides a mechanism to extract and manipulate data from XML documents or any data source that can be viewed as XML. Xpath is a language that describes how to locate specific elements (and attributes, processing instructions, etc.) in a document. FLWR (For, Let, Where, & Result) is the SQL statement equivalents for Xquery to process and restructure data from one or more documents.

6 6 FUNCTIONAL COMPARISON T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

7 7 XSLT DOCUMENT 0 XQUERY JAVA APPLICATION XSLTXSLT XPath 2.0 XQueryXQuery

8 8 APPROACH Both XSLT and XQuery share XPath2.0 as a subset XPath is a language for finding information in an XML document. XPath is used to navigate through elements and attributes in an XML document. XPath is a syntax for defining parts of an XML document XPath uses path expressions to navigate in XML documents XPath contains a library of standard functions T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

9 9 APPROACH SYNTAX DIFFERENCES Syntactical Style of the two languages. 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 } }; T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

10 10 APPROACH FLWOR EXPRESSIONS XQuery ConstructXSLT equivalent for $var in SEQ let $var := SEQ where CONDITION order by $X/VALUE T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

11 11 APPROACH Template based approach and User-defined functions Template-based approach of XSLT can be implemented using XQuery user-defined functions.  Xquery variables are used to model the XSLT context.  Relative XPath expressions are translated into equivalent absolute expressions. Context and relative path expressions XSLT : count(cd/price) XQuery: count(var_t2q/cd/price) T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

12 12 Empire Burlesque Bob Dylan USA Columbia 10.90 1985 Hide your heart Bonnie Tyler UK CBS Records 9.90 1988 Greatest Hits Dolly Parton USA RCA 9.90 1982... APPROACH T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

13 13 APPROACH The notion of match pattern does not exist in Xquery.  Match patterns are translated into equivalent XPath expressions by reversing the pattern. Match patterns XSLT : CD/Title[2]/Artist XQuery: parent_node()/Title[2]/Artist T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

14 14 Empire Burlesque Bob Dylan USA Columbia 10.90 1985 Hide your heart Bonnie Tyler UK CBS Records 9.90 1988 Greatest Hits Dolly Parton USA RCA 9.90 1982... APPROACH Match patterns T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

15 15 APPROACH Templates are translated into equivalent Xquery user defined functions. Templates void t2q_template(Node t2q_node, int t2q_pos, int t2q_size, String t2q mode){ } T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

16 16 Empire Burlesque Bob Dylan USA Columbia 10.90 1985 Hide your heart Bonnie Tyler UK CBS Records 9.90 1988 Greatest Hits Dolly Parton USA RCA 9.90 1982... cdcatalog.xml GROUPING T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

17 17 XSLT version 1.0 (The Muenchian Method developed by Steve Muench.) Key element is use to declares a set of keys Function: node-set key('by-country', country) Key function returns a set of nodes Function: string generate-id(node-set?) XSLT version 2.0 xsl:sort T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 GROUPING

18 18 Population, the sequence of items to be grouped. Grouping keys XSLT version 2.0 <xsl:for-each-group select = expression group-by? = expression group-adjacent? = expression group-starting-with? = pattern group-ending-with? = pattern collation? = { uri } > xsl:sort Assignment to the group depends on these attributes. Only one of these parameters can be specified at any time! T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 GROUPING

19 19 XSLT version 2.0 - Example CD# = T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 GROUPING

20 20 XQuery version 1.0 declare function local:cd-info($cd as element()? ) as element()? { let $t := $cd/title let $a := $cd/artist return Title: {data($t)} Artist: {data($a)} }; for $c in distinct-values(doc("cdcatalog.xml")/catalog/cd/country) return {$c} { for $x in doc("cdcatalog.xml")/catalog/cd where $x/country = $c return {local:cd-info($x)} } CD# = {count(doc("cdcatalog.xml")/catalog/cd[country=$c])} T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 GROUPING

21 21 XSLTXQuery T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 GROUPING

22 22 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 COUPLING BETWEEN XSLT AND XQUERY Even if the languages targets two different user communities, modern applications will increasingly require expertise in both. Ex: Joins are very naturally expressed using XQuery’s “FLWOR” expressions, while XML to HTML conversion is still often easier to write using XSLT’s template-based approach. Popular systems support only one of these two languages, but not the other. Ex: All popular database management systems are planning to support XQuery, but not always XSLT, while some popular editors and libraries support XSLT but not XQuery. For all those reasons, there is a strong need to develop technology which can provide a tight coupling between these two. Reasons

23 23 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 Technical Aspects For some rules we provided detailed compilation for transforming the template based approach of XSLT 2.0 into XQuery’s functional approach. The rules are designed in order to provide the most Natural compilation, so that the resulting program can easily be understood by an experienced XQuery programmer. Covering the complete XSLT language is difficult due to its size and complexity. We identify the fragments of the language that are the most challenging to compile into XQuery, and provide some corresponding solutions. We describe the architecture of that prototype we intend to build and provided examples which demonstrate the feasibility of the approach.

24 24 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 COMPARISON OF XSLT AND TRANSFORMED XQUERY

25 25 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 KNOWLEDGE GAINED XPATH 2.0 XSLT 2.0 XQUERY 1.0 DOM PARSER

26 26 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 References Köhler J (2004), Integration of life science databases, Drug Discovery Today: BIOSILICO, Volume 2, Issue 2, 1 March, Pages 61-69. Jovanovic J, Gasevic D (2005), Achieving knowledge interoperability: An XML/XSLT approach, Expert Systems with Applications, Volume 29, Issue 3, October 2005, Pages 535-553. Kay, M. (2005). Comparing XSLT and XQuery. Proceedings of the XTech 2005 Conference on XML, the Web and beyondComparing XSLT and XQuery. Eisenberg, J. D. (2005). Comparing XSLT and XQuery, last accessed on December 2, 2005 from http://www.xml.com/pub/a/2005/03/09/xquery-v-xslt.htmlhttp://www.xml.com/pub/a/2005/03/09/xquery-v-xslt.html XSLT Tutorial http://www.w3schools.com/xsl/default.asp XQuery Tutorial http://www.w3schools.com/xquery/default.asp Achille Fokoue, Kristoffer Rose et. Al (2005) Compiling XSLT 2.0 into XQuery 1.0, ACM 9/05/2005. http://jenitennison.com/xslt/index.html


Download ppt "1 T RANSFORMING XSLT 2.0 T O XQ UERY 1.0 Advanced Database SystemsCOSC282 G OWRI S HANKAR D ARA T EAM M EMBERS D ARREL M AZZARI A LBIN L AGA A DITYA T."

Similar presentations


Ads by Google