260 likes | 410 Views
T RANSFORMING XSLT 2.0 T O XQ UERY 1.0. COSC282. Advanced Database Systems. T EAM M EMBERS. G OWRI S HANKAR D ARA. D ARREL M AZZARI. A LBIN L AGA. A DITYA T RIPURANENI. T RANSFORMING XSLT 2.0 T O XQ UERY 1.0. OVERVIEW. INTRODUCTION. SYSTEM ARCHITECTURE. APPROACH.
E N D
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 COSC282 Advanced Database Systems TEAMMEMBERS GOWRI SHANKAR DARA DARREL MAZZARI ALBIN LAGA ADITYA TRIPURANENI
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 OVERVIEW INTRODUCTION SYSTEM ARCHITECTURE APPROACH SPECIFIC EXAMPLES CONCLUSION
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 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).
TRANSFORMING XSLT 2.0 TO XQUERY 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.
TRANSFORMING XSLT 2.0 TO XQUERY 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.
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 FUNCTIONAL COMPARISON
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 SYSTEM ARCHITECTURE JAVA APPLICATION XSLT DOCUMENT BUILDING BLOCKS X Q u e r y X S L T XPath 2.0 XQUERY
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 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
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 SYNTAX DIFFERENCES APPROACH Syntactical Style of the two languages. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@* except @NOTE"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> 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 } };
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 FLWOR EXPRESSIONS APPROACH
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 Template based approach and User-defined functions APPROACH Context and relative path expressions • 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. XSLT : count(cd/price) XQuery : count(var_t2q/cd/price)
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 APPROACH <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd> <cd> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <country>USA</country> <company>RCA</company> <price>9.90</price> <year>1982</year> </cd> ... </catalog>
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 APPROACH Match patterns • The notion of match pattern does not exist in Xquery. • Match patterns are translated into equivalent XPath expressions by reversing the pattern. XSLT : CD/Title[2]/Artist XQuery : parent_node()/Title[2]/Artist
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 APPROACH <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd> <cd> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <country>USA</country> <company>RCA</company> <price>9.90</price> <year>1982</year> </cd> ... </catalog> Match patterns
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 APPROACH Templates Templates are translated into equivalent Xquery user defined functions. <xsl:template match =“cd/title”> <xsl:value-of select=“text()”/> <xsl:template> void t2q_template(Node t2q_node, int t2q_pos, int t2q_size, String t2q mode){ }
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 GROUPING cdcatalog.xml <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd> <cd> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <country>USA</country> <company>RCA</company> <price>9.90</price> <year>1982</year> </cd> ... ... </catalog>
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 GROUPING <xsl:keyname="by-country"match="cd" use="country"/> Function: node-set key('by-country', country) Function: string generate-id(node-set?) Key element is use to declares a set of keys Key functionreturns a set of nodes XSLT version 1.0 (The Muenchian Method developed by Steve Muench.) XSLT version 2.0 <xsl:for-each-group select="cd"group-by="country"> <!– Content: (xsl:sort*, sequence-constructor)--> </xsl:for-each-group>
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 GROUPING XSLT version 2.0 Assignment to the group depends on these attributes. Only one of these parameters can be specified at any time! Population, the sequence of items to be grouped. <xsl:for-each-group select= expression group-by? =expression group-adjacent?= expression group-starting-with?= patterngroup-ending-with?= patterncollation? = { uri }> <!– Content: (xsl:sort*, sequence-constructor)--> </xsl:for-each-group> Grouping keys
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 GROUPING XSLT version 2.0 - Example <xsl:stylesheet version="2.0" xmlns:xsl="…"> </xsl:stylesheet> <xsl:template match="catalog"> </xsl:template> <xsl:for-each-group select="cd" group-by="country"> <xsl:value-of select="country"/> CD# = <xsl:value-of select="count(current-group()/title)"/> </xsl:for-each-group> <xsl:for-each select="current-group()"> <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/> </xsl:for-each>
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 GROUPING XQuery version 1.0 declarefunction local:cd-info($cdaselement()? ) aselement()? { let$t := $cd/title let$a := $cd/artist return<p> Title: <span style="color:#ff0000">{data($t)}</span><br/> Artist: <span style="color:#00ff00">{data($a)}</span> </p> }; for$cindistinct-values(doc("cdcatalog.xml")/catalog/cd/country) return <p> {$c} { for$xindoc("cdcatalog.xml")/catalog/cd where$x/country = $c return<li>{local:cd-info($x)}</li> } CD# = {count(doc("cdcatalog.xml")/catalog/cd[country=$c])} <p/> </p>
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 GROUPING XSLT XQuery
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 COUPLING BETWEEN XSLT AND XQUERY Reasons 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.
TRANSFORMING XSLT 2.0 TO XQUERY 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.
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 COMPARISON OF XSLT AND TRANSFORMED XQUERY
TRANSFORMING XSLT 2.0 TO XQUERY 1.0 KNOWLEDGE GAINED XPATH 2.0 XSLT 2.0 XQUERY 1.0 DOM PARSER
TRANSFORMING XSLT 2.0 TO XQUERY 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 beyond 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.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