Title: Translating XQuery into XSLT
1Translating XQuery into XSLT
- Stephan Lechner, Günter Preuner, Michael Schrefl
- Johannes Kepler University of Linz
- Homepage http//www.dke.uni-linz.ac.at
2Contents
- Introduction
- XQuery to XSLT Differences to bridge
- Translation and Transformation
- XQ2XSL-Translator
- Conclusion
31. Introduction
- XSLT
- Transformations and presentational markup
- Adopted by industry (e.g. in Web-Browsers)
- Most beneficial Client Side Processing
- XQuery
- Typed query language for XML documents
- Most beneficial Server Side Processing
- Comfortable to use
4Scenario Different Views of Data
Authors and Books (XML)
Authors View (XSL)
Books View (XSL)
Client Side
Server Side
5Views using XQuery and XQ2XSL
Authors View Transfor- mations (XQuery)
Templates For Presentation (XSL)
Authors View Presentation (XSL)
Authors View Transfor- mations (XSL)
XQ2XSL
Combine
Authors and Books (XML)
Authors View (XSL)
works on
6Motivation
- Expressing complex transformations for views
conveniently using XQueries - Perform these transformations on Client Side
using XSLT only (yet implemented by many
browsers)
72. XQuery to XSLT Differences
- Different data models
- Node identity
- Interim query results
- Different language constructs
- Closure
- Parameter binding byposition vs. name
- Nested variables scopes
8Bridging Data Model Differences
- To avoid case-distinctions, we use an Internal
Data Model with... - Explicit Node Identifiers
- Wrapper elements around attributes, PIs, comments
9Language Construct Differences
- FOR b
- IN annualBooks(2001)
- RETURN
- LET b b/title
- RETURN b
- ltvariable name"FOR1_outer"gt
- ltcall-template name"annualBooks"gt
- ltwith-param name"yearParam"
- select"2001"/gt
- lt/gtlt/gt
- ltfor-each select"FOR1_outer/"gt
- ltvariable name"FOR1 select"."/gt
- ltvariable name"LET1"gt
- ltcopy-of select"FOR1/title"/gt
- lt/gt
- ltcopy-of select"LET1"/gt
- lt/gt
103. Translation and Transformation
114. XQ2XSL Translator
- Parse tree generation and augmentation
- Names of auxiliary variables
- Aliases for XQuery-variables
- Determine parameter names and positions
- Node Translation
- Traverse the parse tree (depth first)
- Translate each node
12Parse Tree Generation Augmentation
LET b b/title RETURN b
letexp LET Variablevar EQUAL
Exprouter RETURN Exprinner
Alias(b)Let1
13FOR b IN annualBooks(2001) RETURN LET b
b/title RETURN b
Param- pos1
Var
b
Proj
Var
Alias(b) Let1
b
14Implementation CUP Parser Generator
Grammar (production)
- letexp LET Variablevar
- EQUAL Exprouter
- RETURN Exprinner
- Node n new LetExpressionNode ()
- n.setChild ("Variable", var)
- n.setChild ("OuterExpression", outer)
- n.setChild ("InnerExpression", inner)
- var.setParent (n)
- outer.setParent (n)
- inner.setParent (n)
- inner.setAlias (var.getLiteralValue(),
- Node.newAlias())
- RESULT n
-
Parse Tree Generation and Augmentation using Seman
tic Actions
15Parse Tree Traversal Node Translation
AN
16Node Translation by Transition Rules
IF (Type(AN) LetExpression) THEN NV(AN)
ltvariable name1"gt2lt/gt3
1 Alias (Child (inner), LitValue
(Child (var)) 2 NV (Child (outer)) 3 NV
(Child (inner))
17Implementation Node Translation (Java)
- class LetExpressionNode extends Node
- void translate ()
- // Depth-first traversal
- getChild (var").translate ()
- ... translate the other children
-
- // get values for the place holders
- String alias getChild(inner).
- getAlias (getChild
(var).getLiteralValue()) - ... values of the other place holders
- // Evaluate the value of "self"
- setNodeValue ("ltxslvariable name\""
- alias ... )
-
-
185. Conclusion
- Advantages of XQuery High-level query language
with type-checking - Advantages of XSLT well suited for
presentational markup, widely distributed and
adopted by industry - Translating XQuery into XSLT complex
transformations can be expressed in XQuery and
performed as XSLT.
19Future Work
- Automatic splitting of XQueries into server-side
and client-side parts - Parameterizing XQueries for personalization
purpose - Extending the concept by runtime type information
20(No Transcript)
21(a) Views Data defined by XQueries
Authors and Books (XML)
Authors View Transfor- mations (XQuery)
Templates For Presentation (XSL)
Authors View Presentation (XSL)
XQuery
Combine
Authors View (XSL)
Authors View Data (XML)
works on