Transforming XSLT stylesheets into XQuery expressions and vice versa

https://doi.org/10.1016/j.cl.2010.11.001Get rights and content

Abstract

XSLT and XQuery are the languages developed by the W3C for transforming and querying XML data. XSLT and XQuery have the same expressive power and can be indeed translated into each other. Many tools either support XSLT or XQuery. In this paper, we show how to translate XSLT stylesheets into equivalent XQuery expressions and vice versa, so that we can apply the same tools to both languages. We also present a performance analysis that compares the execution times of the translation of the original query and of its translated expression using various current XSLT processors and XQuery evaluators.

Introduction

Today, we use more and more of XML's capability of labeling the information content of diverse data sources, including structured and semi-structured documents, relational databases, and object repositories. Furthermore, native XML databases have occurred in recent years. The W3C developed the Extensible Stylesheet Language (XSL) [30], [31] and especially its XSL Transformations (XSLT) [35], [36] part which can express transformations of XML data, and later the XQuery [34] language, which can express queries.

Although both languages are developed with different aims, their application possibilities and expressive power are similar. Both languages use XPath [32], [33] as the path language for retrieving XML node sets and both have corresponding language constructs for iterations on an XML node set, definitions of variables, XML node constructors and definitions and calls of user-defined functions. Thus, we can construct a translation from XSLT stylesheets into XQuery expressions and vice versa. Let E be the original expression formulated in XSLT or XQuery and let E’ be the translated expression formulated in the other language. Let E(D1, …, Dn) and E’(D1, …, Dn) be results of applying E and E’, respectively, to the input XML documents D1, …, Dn1, then we call a translation of E into E’ correct if the following holds for all input XML documents D1, …, Dn: E(D1, …, Dn)=E’(D1, …, Dn).

Many tools support either XSLT or XQuery, but not both. In the following, we describe application scenarios, where the application of a translation from XQuery expressions into XSLT stylesheets and a translation from XSLT stylesheets into XQuery expressions has considerable benefits.

  • (1)

    Translation from XQuery expressions into XSLT stylesheets: Using our proposed translation from XQuery expressions into XSLT stylesheets, the XQuery language can be used whenever commercially or freely available products support the processing of XSLT stylesheets, but do not support the XQuery language. Examples of such tools are BizTalk [23], Cocoon [1] and Xalan [2].

  • (2)

    Translation from XSLT stylesheets into XQuery expressions: Many commercially or freely available products support the evaluation of XQuery expressions, but do not support the XSLT language, for example, Tamino XML Server [28], Microsoft SQL Server 2005 Express [24], Galax [9] and Qizx [11]. A translation module from XSLT stylesheets into XQuery expressions can make the XSLT language available for these products. Another usage scenario is the migration of legacy systems. Legacy systems may use sub-systems which support XSLT. Furthermore, legacy systems may be migrated to sub-systems which support the new language XQuery instead of XSLT. Then, a translation module can be used to translate the old XSLT stylesheets into equivalent XQuery expressions, so that those expressions can be applied instead. Note that XSLT has been used in companies for a longer time than XQuery, thus many applications already use XSLT. Furthermore, many XSLT stylesheets for different purposes can be found on the web, but the new XQuery technology becomes more and more apparent in the market to be the query language of XML databases and XML enabled databases. Database systems have many advantages, such as support of the transaction concept, improved backup and recovery services, data consistency, improved data integrity, sharing of data, increased concurrency and improved security. If a user wants to use an XML database or an XML enabled database in order to benefit from the advantages of a database system, the user must use the XQuery language as the native language for most database systems. Again, when using our translation approach, the user can also formulate queries in the XSLT language and afterwards apply an XSLT to the XQuery translator.

  • (3)

    Cloud computing offering XML services on heteregenous software configurations: A cloud (e.g. [5]) consists of a group of computers that offers services to users. The location of service processing is hidden to the user by the cloud, i.e. users can use a service in the cloud without caring about how and where the service is performed. Cloud computing distributes service processing according to current workload of its computers and the configurations of these computers in order to achieve a high performance of the single service and a high overall performance. Over time, new computers are added to clouds and clouds, hence, usually consist of heterogenous hard- and software. In our application scenario, we assume that a cloud offers XML services supporting XQuery and XSLT processing. A computer in the cloud may have an XSLT processor, an XQuery engine, both, or none. Furthermore, not every XSLT processor and XQuery engine works well and with high performance on every hardware configuration, e.g. while a main memory XSLT processor works well for small data sets already on netbooks, an XML database often needs a server, but can also process large-scale data sets with high performance. It is essential for best performance in the cloud that the distribution of tasks can be done with most possible flexibility. Therefore, we need an XSLT to XQuery translation as well as an XQuery to XSLT translation to support distributing XQuery querying tasks also to computers with an XSLT processor and XSLT transformation tasks to computers with an XQuery engine.

The rest of the paper is organized as follows. Section 2 introduces the basic concepts of XPath, XSLT, XQuery, EBNF, abstract syntax trees and attribute grammars. Section 3 describes a source-to-source translation from XSLT stylesheets into XQuery expressions, and Section 4 describes the source-to-source translation of the opposite direction from XQuery expressions into XSLT stylesheets. Section 5 presents a performance analysis comparing the execution times of original queries and their translated expressions, where both translation directions, from XSLT to XQuery and from XQuery to XSLT, are considered. Section 6 discusses the related work. Section 7 completes our paper with the summary and conclusions. Finally, Appendix A presents more details about the translation processes in the form of attribute grammars.

Section snippets

Essentials

In this section, we present the essentials that are necessary to understand this paper. In particular, we introduce the XPath language (Section 2.1), the XQuery language (Section 2.2) and the XSLT language (Section 2.3). In Section 2.4, we introduce EBNF, which we use for abstract syntax trees representing the syntactical structure of a program formulated either in XSLT or XQuery, and we introduce attribute grammars, which we use for representing the source-to-source translation algorithms.

Translating XQuery expressions into XSLT stylesheets

In this section, we propose a translation from XQuery expressions into XSLT stylesheets. Using this translation, the XQuery language can be used in combination with commercially or freely available products that support the processing of XSLT stylesheets, but do not support the XQuery language, for example, BizTalk [23], Cocoon [1] and Xalan [2]. We describe the differences between XSLT and XQuery in handling intermediate results in Section 3.1, and the differences in the language constructs of

Translating XSLT stylesheets into XQuery expressions

In this section, we propose a translation from XSLT stylesheets into XQuery expressions. The translated XQuery expression has to simulate different functionalities of XSLT. Since the XQuery language does not support templates, the translated XQuery expression has to simulate the template selection process (Section 4.1). For the template selection process, we present two different approaches: the match node sets approach (Section 4.1.1) and the reverse pattern approach (Section 4.1.2). Besides

Performance analysis

This section describes the experiments that we have conducted to compare the execution times of translated queries with those of the original queries. The experimental environment is described in Section 5.1 including the test system (Section 5.1.1), the XMark benchmark [27] (Section 5.1.2) and the XSLTMark benchmark [4] (Section 5.1.3), which contain the queries we use in the experiments. We present the experimental results of translating XQuery expressions into XSLT stylesheets in Section 5.2

Related work

[22] shows that many XQuery constructs can easily be mapped to XSLT, but presents only examples of mappings and does not provide an algorithm for translating XQuery expressions into XSLT stylesheets.

Furthermore, [18], [21], [22] present an algorithmic approach of translating XQuery expressions into XSLT stylesheets, which is one direction of our proposed translations. However, even for this direction, neither [18] nor [21] nor [22] presents a complete translation algorithm as we present in this

Summary and conclusions

In this paper, we proposed approaches to translate XSLT stylesheets into XQuery expressions and vice versa.

The main difficulty for the translation from XSLT stylesheets into XQuery expressions is to simulate the template selection of XSLT. One task for the simulation of the template selection process of XSLT is to check whether a pattern matches an XML node. We proposed two different methods for this test. The first method, called the match node sets approach, uses match node sets containing a

References (35)

  • Apache Software Foundation. Cocoon, 〈http://cocoon.apache.org〉;...
  • Apache Software Foundation. Xalan-Java, 〈http://xml.apache.org/xalan-j/index.html〉;...
  • Ralf Bettentrupp, Sven Groppe, Jinghua Groppe, Stefan Böttcher, Le Gruenwald. A Prototype for Translating XSLT into...
  • Developer. XSLT Mark version 2.1.0, 〈http://www.datapower.com/xmldev/xsltmark.html〉;...
  • Douglis Fred

    Staring at clouds

    IEEE Internet Computing

    (2009)
  • Matthias Droop, Markus Flarer, Jinghua Groppe, Sven Groppe, Volker Linnemann, Jakob Pinggera, Florian Santner, Michael...
  • Matthias Droop, Markus Flarer, Jinghua Groppe, Sven Groppe, Volker Linnemann, Jakob Pinggera, Florian Santner, Michael...
  • Matthias Droop, Markus Flarer, Jinghua Groppe, Sven Groppe, Volker Linnemann, Jakob Pinggera, Florian Santner, Michael...
  • Fernández M, Siméon J, Chen C, Choi B, Dinoff R, Gapeyev V, Marian A, Michiels P, Onose N, Petkanics D, Radhakrishnan...
  • Fokoue A, Rose K, Siméon J, Villard L. Compiling XSLT 2.0 into XQuery 1.0. WWW 2005, Chiba, Japan;...
  • Franc X. Qizx/open version 0.4p1, 〈http://www.xfra.net/qizxopen/〉;...
  • Sven Groppe, Jinghua Groppe, Volker Linneman, Dirk Kukulenz, Nils Hoeller, Christoph Reinke. Embedding SPARQL into...
  • Torsten Grust, Manuel Mayr, Jan Rittinger. Let SQL drive the XQuery workhorse (XQuery join graph isolation). In: 13th...
  • Grust T, Sakr S, Teubner J. XQuery on SQL Hosts. In: Proc. VLDB,...
  • International organization for standardization (ISO). ISO/IEC 14977:1996: Information technology – Syntactic...
  • Jain S, Mahajan R, Suciu D. Translating XSLT programs to efficient SQL queries. In: Proceedings of the Eleventh...
  • Kay MH. Saxon—The XSLT and XQuery processor, 〈http://saxon.sourceforge.net〉; April...
  • Cited by (0)

    View full text