26
1 TRANSFORMING XSLT 2.0 TO XQUERY 1.0 Advanced Database Systems COSC282 GOWRI SHANKAR DARA TEAM MEMBERS DARREL MAZZARI ALBIN LAGA ADITYA TRIPURANENI

T RANSFORMING XSLT 2.0 T O XQ UERY 1.0

  • Upload
    kadeem

  • View
    40

  • Download
    0

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

1

TRANSFORMING XSLT 2.0 TO XQUERY 1.0Advanced Database SystemsCOSC282

GOWRI SHANKAR DARA

TEAM MEMBERS

DARREL MAZZARI

ALBIN LAGA

ADITYA TRIPURANENI

Page 2: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

2

OVERVIEW

INTRODUCTION

SYSTEM ARCHITECTURE

APPROACH

SPECIFIC EXAMPLES

CONCLUSION

TRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 3: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

3

TRANSFORMING XSLT 2.0 TO XQUERY 1.0WHY 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).

Page 4: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

4

TRANSFORMING XSLT 2.0 TO XQUERY 1.0Definitions

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.

Page 5: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

5

TRANSFORMING XSLT 2.0 TO XQUERY 1.0Definitions

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.

Page 6: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

6

FUNCTIONAL COMPARISON

TRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 7: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

7

XSLT DOCUMENT

XQUERY

BUILDING BLOCKS

SYSTEM ARCHITECTURE

JAVA APPLICATION

XSLT

XPath 2.0

XQuery

TRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 8: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

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

TRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 9: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

9

APPROACH SYNTAX DIFFERENCES

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

Page 10: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

10

APPROACH FLWOR EXPRESSIONS

XQuery Construct

XSLT equivalent

for $var in SEQ<xsl:for-each select="SEQ"> <xsl:variable name="var"

select="."/>

let $var := SEQ <xsl:variable name="var" select="SEQ"/>

where CONDITION <xsl:if test="CONDITION">

order by $X/VALUE <xsl:sort select="VALUE"/>

TRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 11: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

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)

TRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 12: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

12

<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>

APPROACH

TRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 13: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

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]/ArtistXQuery : parent_node()/Title[2]/Artist

TRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 14: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

14

<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>

APPROACH

Match patterns

TRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 15: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

15

APPROACH

Templates are translated into equivalent Xquery user defined functions.

Templates

<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

Page 16: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

16

<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>

cdcatalog.xml GROUPINGTRANSFORMING XSLT 2.0 TO XQUERY 1.0

Page 17: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

17

XSLT version 1.0(The Muenchian Method developed by Steve Muench.)

Key element is use to declares a set of keys

<xsl:key name="by-country" match="cd" use="country"/>

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:for-each-group select="cd" group-by="country"><!– Content: (xsl:sort*, sequence-constructor) -->

</xsl:for-each-group>

TRANSFORMING XSLT 2.0 TO XQUERY 1.0GROUPING

Page 18: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

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 }>

<!– Content: (xsl:sort*, sequence-constructor) -->

</xsl:for-each-group>

Assignment to the group depends on these attributes.Only one of these parameters can be specified at any time!

TRANSFORMING XSLT 2.0 TO XQUERY 1.0GROUPING

Page 19: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

19

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.0GROUPING

Page 20: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

20

XQuery version 1.0declare function local:cd-info($cd as element()? ) as element()?

{

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 $c in distinct-values(doc("cdcatalog.xml")/catalog/cd/country)

return

<p>

{$c}

{

for $x in doc("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.0GROUPING

Page 21: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

21

XSLT XQuery

TRANSFORMING XSLT 2.0 TO XQUERY 1.0GROUPING

Page 22: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

22

TRANSFORMING XSLT 2.0 TO XQUERY 1.0COUPLING 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

Page 23: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

23

TRANSFORMING XSLT 2.0 TO XQUERY 1.0Technical 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.

Page 24: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

24

TRANSFORMING XSLT 2.0 TO XQUERY 1.0COMPARISON OF XSLT AND TRANSFORMED XQUERY

Page 25: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

25

TRANSFORMING XSLT 2.0 TO XQUERY 1.0KNOWLEDGE GAINED

XPATH 2.0

XSLT 2.0

XQUERY 1.0

DOM PARSER

Page 26: T RANSFORMING  XSLT 2.0 T O  XQ UERY  1.0

26

TRANSFORMING XSLT 2.0 TO XQUERY 1.0References

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 Tutorialhttp://www.w3schools.com/xsl/default.aspXQuery Tutorialhttp://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