XML Schema Driven Generation of Architecture Components and Integration of on-line and off-line Systems

Ali El bekai, Nick Rossiter
Informatics School, Northumbria University
Email: ali.elbekai@unn.ac.uk, nick.rossiter@unn.ac.uk

Keywords:  XML Schema, XQuery, SQL, DOM, XSL stylesheet

Abstract: 
It is possible to code by hand an XSL stylesheet that validates an XML document against some or all constraints of an XML schema. But the main goal of this paper introduces general techniques as a technology solution for different problems such as (a) generation of SQL schema from XMLSchema, (b) generating XSL stylesheet from XMLSchema, and (c) XQuery interpreter generating. Each of the techniques proposed in this paper works by XMLSchema-driven generation architecture components with XSL stylesheet. As can be seen the input is XMLSchema and XSL stylesheet and the output is generic stylesheets. These stylesheets can be used as interpreter for generating other types of data such as SQL queries from XQueries, SQL data, SQL schema and HTML format. The XSL stylesheets we present are a part of our developing the technology of the system. Furthermore, we present algorithms for these types of generation. These algorithms show how we can generate these components automatically. We also introduce examples to evaluate the generated components.
 
1 INTRODUCTION 

XML [Chawathe 1999, W3C 2000] is fast emerging as the dominant standard for representing and exchanging information over the Internet. If data is stored and represented as XML documents, then it should be possible to query the contents of these documents in order to extract, synthesize and analyze their contents. Also, it is possible to transform theses data to another format and to generate a component from the XML data.  Again XML and its surrounding technologies have many things in common with real databases, storage (XML documents), schemas (DTDs, XML schema languages), query languages (XQuery, XPath, XQL, XML-QL, QUILT, etc.), and programming interfaces (SAX, DOM, JDOM). On the other hand, XML lacks to some extents many database facilities as described in Section 2 [Bourret 2004, Florescu et al 99]. Furthermore, over recent years, XML has achieved a remarkable success in handling structured data access in the web, and has been increasingly recommended and supported by major software vendors [Bourret 2004].
In fact, XML without database technology is intended for presentation to an end user. Originally, XML was created to meet the challenges of data exchange is Web applications or between applications and users, not data presentation purposes. To deal with presentation issues, XML needs to be used in conjunction with stylesheets to be easily viewed on the web. For this reason, eXtensible Stylesheet Language was created. XSL (Extensible Stylesheet Language) is being developed as part of the W3C stylesheets activity [W3C 2000, W3C 99]. It is evolved from the CSS language to provide even richer stylistic control, and to ensure consistency of implementations. It also has document manipulation capabilities beyond styling. 
     Of course, designing “traditional” software transformation tools for that purpose can achieve such a task. However, the power of having a cross-platform and XML independent language would be lost. Precisely, isolating content from formatting needs to be considered, especially when dealing with Web based documents. Therefore, any method of transforming XML documents into different formats such as XML, HTML, SQL, flat files or WML needs to be tailored so that it can be used in different platforms/languages. As we mentioned it is possible to code by hand an XSL stylesheet that validates an XML document against some or all constraints of XML schema [Peterson et al 2004]. But this paper introduces the technological solutions for different problems such as (a) SQL schema generation, (b) XSL stylesheet generation, and (c) XQuery interpreter generation automatically by transforming an XMLSchema through an XSLT. The resulting XSL stylesheet can then be used for transforming XML documents to other formats such as SQL statement, HTML format and SQL queries. 
    The rest of the paper is structured as follows: Section 2 presents the related work for XML and the techniques for generating XML data. This leads up to our technique for generating SQL schema in Section 3. Subsection 3.1 introduces an example to evaluate the technique. Section 4 presents our technique for generating XSL and Subsection 4.1 introduces an example to evaluate the technique. Section 5 presents the XQuery interpreter generation technique. Subsection 5.1 introduces examples to evaluate the technique.  Section 6 summarizes the techniques and conclusion. 

2 RELATED WORK

[Bourret 2004] noted that XML and its surrounding technologies have many facilities in common with real databases such as storage (XML documents), schemas (DTDs, XML schema languages), query languages (XQuery, XPath, XQL, XML-QL, QUILT, etc.), and programming interfaces (SAX, DOM, JDOM). On the other hand, XML lacks efficient storage, indexes security, transactions and data integrity, multi-user access, triggers, queries across multiple documents, and so on. [Aboulnaga, et al 2001] started a discussion in the XML community about characterizing and generating XML data. [Yuan Wang, et al 2002] and proposed X-Diff, an algorithm that integrates key XML structure characteristics with standard tree-to-tree correction techniques. [Provost 2002] considered the most common patterns for document content constraints, and finds that XML Schema validation is only the first of several necessary layers. XPath and XSLT are discovered to be effective tools for document validation, and able to assert constraints that are too complex for schema. Validation architecture is developed which relies entirely on W3C-recommended standards, using XML Schema validation, XPath/XSLT validation and code-level checking in the XML application. [Bourret 2004] summarized two different mappings. The first part of the process, generally known as XML data binding, maps the W3C's XML Schemas to object schemas. The second known as object-relational mapping, maps object schemas to relational database schemas. [Braganholo 2002] presents an overview of a process for updating relational databases through XML views. The process is based on a query language called R2X and on a concept of normalization for XML views. The R2X language constructs XML views from relational databases, while normalization removes the ambiguity in an XML view, thus solving the update problem.  [Shanmugasundaram et al 2001] presents a technique for querying XML documents using a relational database system, which (a) enables the same query processor to used with most relational schema generation techniques. [Norton 99] presents an XSL as validation to validate XML document. [Manolescu et al 2001] describe a query processor that works for different schema generation techniques. Their work is done in the context of data integration, and the tables generated by each relational schema generation technique are specified as materialized views over a virtual global schema.  [DeHaan et al 2003] presents a translation of XQuery expression drawn from a comprehensive subset of XQuery to a single equivalent SQL query using a novel dynamic interval encoding of a collection of XML documents. [Krishnamurthy et al 2004] They present an algorithm that translates simple path expression queries to SQL in the presences of recursion in the schema in the context of schema-based XML storage shredding of XML relations.
      As a result none of them introduce an algorithm to generate a generic XSL stylesheet for transforming XML to SQL statements or an XSL stylesheet for transforming XQueries to SQL queries or for generating SQL schema by using XSL. This paper will introduce general algorithms to generate these components automatically. The generated components can then be used in different kinds of transformation. In the following sections we will introduce these general techniques in more details. 

3. SQL SCHEMA GENERATIONS 

Basically, the DOM [W3C 2002, W3C 2003] is a specification that comprises a set of interfaces that allow XML documents to be parsed and manipulated in memory. These interfaces are defined by the W3C who provide application-programming interfaces (APIs) for every major programming language using the Interface Definition Language. To be precise, the DOM is not designed specifically for Java, but to represent the content and model of documents across all programming languages and tools. Bindings exist for JavaScript, Java, CORBA and other languages, allowing the DOM to be a cross-platform and cross-language specification. DOM has been specifically designed by the W3C to model XML documents in a tree structure, beginning with a root element and comprising any number of child and sibling nodes. When an XML document is parsed by DOM, the entire content of the document is read into memory and providing it is a well-formed document, is then represented in the tree structure. The elements can then be accessed and traversed from the root node using the tree relationships. The main interfaces for an application with DOM are: Node: the base type, representing a node in the DOM tree. Document: representing the entire XML document as a tree of Nodes (the DOM parser will return Document as a result of parsing the XML). Element: to represent the elements of the XML document. Attribute, representing an attribute of some XML element; the interface enables setting/getting the value of that attribute. Text: to represent the text content of an element (i.e. the text between tags that is not part of any child element). The DOM tree is composed of nodes, each of which represents a parsed document. Based on these interfaces, we will use the XMLSchema parse file (DOM) as input in our algorithm to generate the components automatically. Now we will introduce an algorithm that can be used automatically to generate the SQL schema as output of an arbitrary XMLSchema. In particular, we present a translation algorithm that takes as input an XMLSchema and XSL stylesheet and produce a SQL schema as the output. In other words this algorithm is as the technology solution to the problem of generating SQL schema. An algorithm is shown in Figure 1 for generating SQL Schema from XMLSchema. In the following section we will show how the algorithm works and how we can generate the SQL schema, which is equivalent to an XMLSchema. 

 Algorithm generate SQL Schema (XMLSchema (DOM), XSL stylesheet)  
 // Input XMLSchema, XSL stylesheet
 // Output SQL Schema  (SQL DDL)
  1. start
  2.  if the input arguments of the algorithm (XMLSchema, XSL stylesheet) exist
       2.1 Build DOM and parse it
       2.2 if parsing XMLSchema is done then DOM will build dynamically
             2.2.1 perform XSL stylesheet transformation
             2.2.2 if transformation is done
                   2.2.2.1 transformation processing (XMLSchema, XSL stylesheet)   
                   2.2.2.2 the XSL stylesheet template adds SQL clause CREATE TABLE to the 
                              start of each separate SQL table followed by the matching complexType 
                              node of the DOM tree
                   2.2.2.3 for each complexType create a separate SQL table
                              2.2.2.3.1 generate a primary key to each SQL table as table name and 
                                              followed by the string “_id” 
                              2.2.2.3.2 generate the foreign key to the appropriate table name followed 
                                             by the string “_fk” or identify child node and map them as foreign  
                                             key to the SQL table as in our example
                              2.2.2.3.3 If the root node (complexType) has parent/child nodes
                                             2.2.2.3.3.1 the XSL stylesheet template matches and maps all    
                                                              child nodes of DOM tree as column names to created   
                                                              SQL tables  
                                             2.2.2.3.3.2 the XSL stylesheet templates walk through DOM and
                                                               matches the attribute nodes and data types 
                                             2.2.2.3.3.3 map attribute nodes and data types to column names
                                                               in SQL table as data types
                              2.2.2.3.4 report no parent/child node and terminate   
                   2.2.2.4 finish the execution, the SQL schema is generated      
             2.2.3 report transformation errors and terminate
       2.3  report parsing errors and terminate
3.  report reading errors and terminate  
4.  terminate          

                          Figure 1: Algorithm to generate SQL Schema from XMLSchema

        

3.1 How the Algorithm Works  

To illustrate how the algorithm shown in Figure 1 works, let us walk through the algorithm, since the input to the algorithm is a fragment of our XML Schema containing information for the museum objects such as collections, objects, objectInformation, exhibition, and institution shown in Figure 2 and the generated XSL stylesheet (GenericSQL.xsl) shown in Figure 3. If the inputs of the algorithm exist, “Build DOM and parse it” (XMLSchema). While the parsing is executed (line 3.1 in Figure 1) DOM tree will build dynamically. Then perform the XSL stylesheet shown in Figure 3. If the transformation is done (line 3.2.2 in Figure 1) the algorithm is invoked with the root node of the XMLSchema and complexType name (collection, object, objectInformation, exhibition, institution and staff in our example), the XSL stylesheet templates will match the node in DOM tree (i.e. <xsl: template match =”…”>) and map the complexType node to the separate SQL table as table name (line 3.2.2.2 in Figure 1). If the complexType (root node) has parent/child nodes (line 3.2.2.3 in Figure 1) the XSL stylesheet templates walk through DOM tree nodes and map the child node to corresponding column name in the SQL table (line 3.2.2.3.1 in Figure 1). Next, the XSL stylesheet iterate through the DOM tree nodes and maps the data types to corresponding types in SQL schema such as VARCHAR, DATE, CHAR and INTEGER (line 3.2.2.3.2 in Figure 1). The XSL stylesheet applies the matched template for the child nodes of the DOM and maps them as column names in SQL table. The result is returned to all templates and the SQL tables are generated (SQL schema line 3.2.2.3.3 in Figure 1). At the end we add SQL CREATE TABLE into the generated SQL then returns the result.  
     As a result Figure 4 shows the generating of SQL Schema after we used the generated XSL stylesheet. It also shows generation of multiple Data Definition Language (DDL) SQL tables related to the via foreign keys. The first SQL collection table has many column names such as collection_id, num, name, publishing_date, remote, features, purpose, description and URL. While the exh-exh-id, inst-inst-id and staf-staf-id are the foreign keys for the collection table. 
The second DDL SQL table similarly defines an object table with column names, data types and foreign keys such as staf_staf_id, cllctn_cllctn_id and inst_inst_id. The third SQL table is objcetInformation, which has many column names and foreign keys such as obj_obj_id, inst_inst_id and exh_exh_id. 
Moreover, the SQL schema has SQL tables such as institution table, exhibition table, reference and staff tables. Each table has column names, data types and foreign keys. 
     Finally, to conclude we can generate automatically any SQL schema needed by using the generated XSL stylesheet (generator) shown in Figure 3. The example below shows how the generator works, but it should be noted that the XSL stylesheet is generic, which means the generator is valid for generating any SQL schema from any XML Schema. Furthermore as we mentioned early this algorithm is the technology solution to the problem of SQL schema generation. 

                                                            Figure 2: A fragment of our XMLSchema
       
       Figure 3:  Generic XSL Stylesheet (GenericSQL.xsl) to generate SQL Schema from XMLSchema

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/ 1999/XSL/Transform">
<xsl:template match="complexType">
DROP TABLE IF EXISTS <xsl:value-of select="@name" />;
CREATE TABLE <xsl:value-of select="@name" />
(<xsl:value-of select="@name" />_id INT NOT NULL,
<xsl:apply-templates select="element" mode="@name" />
PRIMARY KEY (<xsl:value-of select="@name" />_id) )
</xsl:template>
<xsl:template match="element" mode="@name">
<xsl:value-of select="@name" />
<xsl:apply-templates select="@type" mode="schematype" />
</xsl:template>
<xsl:template match="@type" mode="schematype">
<xsl:variable name="type" select="." />
      <xsl:choose>
<xsl:when test="$type='String'">VARCHAR2 (*)</xsl:when>
<xsl:when test="$type='Date'">DATE NOT NULL</xsl:when>
<xsl:when test="$type='Text'">TEXT</xsl:when>
<xsl:when test="$type='Integer'">INTEGER (10,0) NOT NULL</xsl:when>
<xsl:when test="$type='Image'">IMAGE</xsl:when>
<xsl:when test="$type='Url'">URL</xsl:when>
<xsl:when test="$type='Char'">CHAR (1)</xsl:when>
<xsl:when test="$type='Sex'">SEX</xsl:when>
<xsl:when test="$type='BLOB'">BLOB</xsl:when>
<xsl:when test="$type='Country'">COUNTRY</xsl:when>
<xsl:when test="$type='ReferenceType'">ReferenceType</xsl:when>
      </xsl:choose>,
</xsl:template>
</xsl:stylesheet>

Figure 4: SQL Schema generated after using XSL Stylesheet (generator) 

4 XSL GENERATIONS

Basically, it is possible to code by hand an XSL stylesheet that validates an XML document against some or all constraints of an XML schema. But in this section we introduces an algorithm as shown in Figure 5 for generating an XSL stylesheet from an XMLSchema parse file (DOM) and as mentioned before the DOM tree is composed of nodes, each of which represents a parsed document. In other words this algorithm is the technology solution to the problem of generating an XSL automatically by transforming an XMLSchema through an XSLT. The result is a generic XSL stylesheet providing the mechanism to transform and manipulate XML data. Also the generated XSL stylesheet can be used to transform XML document into other formats such as XML to SQL statements and XML to HTML document as can be seen in the following subsections. 

                                          Figure 5: Algorithm for generating XSL from XMLSchema  

// Input XMLSchema, XSL stylesheet, // output XSL stylesheet
  1.  start
  2.  checking arguments (XMLSchema, XSL stylesheet)
  3.  If argument exists
       3.1 Building DOM and parsing it
       3.2 if parsing XMLSchema is ok DOM will build dynamically
             3.2.1 perform XSL stylesheet(each XSL stylesheet contains templates and commands to select
                      and manipulate structure of data)
             3.2.2 if transformation is ok
                      3.2.2.1 invoke the root node of DOM tree
                      3.2.2.2 compare the root node with template rules in the stylesheet, it match the first one
                                  then mapped to root node of an XSL stylesheet output (as new template)
                      3.2.2.3 If the root node has parent/child nodes
                                  3.2.2.3.1 the XSL walks through DOM tree and pulls nodes from DOM tree and  
                                                 places it with formatting as a new templates to output 
                                  3.2.2.3.2 compare and match the child node of the DOM tree with the XSL template
                                                 and set it as new XSL template in to the output     
                                  3.2.2.3.3 iterate through the DOM tree child nodes and pulls and place it as output
                                                 in the new XSL stylesheet
                                  3.2.2.3.4 insert the required statement and return all templates then (new XSL 
                                                 stylesheet generated)
                      3.2.2.4 report no parent/child node and terminate   
             3.2.3 report transformation errors and terminate
       3.3 report parsing errors and terminate
  4. report reading errors and terminate
  5. terminate/end         

      

4.1 How the Algorithm Works 
To test the algorithm shown in Figure 5 we will use the input parameters, of the algorithm (XSL stylesheet and the XMLSchema). Let us walk through the algorithm by using the XMLSchema code shown in Figure 2 as an input data for testing the algorithm. The algorithm is invoked by checking the arguments exist (inputs of the algorithm). If they exist then we parse the XMLSchema and the DOM tree will build dynamically (line 3.2 in Figure 5). Then we perform the XSL stylesheet, for each template in the XSL stylesheet, match a node in DOM tree and invoke the transformation from the root node of DOM tree (line 3.2.1-3.2.2.1 in Figure 5).

The XSL stylesheet templates walk through the DOM tree, pulling out child nodes of DOM tree and placing them as formatted to the output as generated templates (lines 3.2.2.2-3.2.2.3 in Figure 5). Next, the XSL stylesheet templates will compare and match the child nodes of DOM tree and then generate a new template for the output (line 3.2.2.3.2 in Figure 5) root node. The execution returns all a new templates generated as the output (line 3.2.2.3.3 in Figure 5). Then the output of the algorithm will be generic XSL stylesheets generated from existing XMLSchema which parses file automatically as shown in Figure 6.

                                                 

                                            Figure 6: Generic XSL is generated of the algorithm in Figure 5

In addition, we introduce a generic stylesheet for transforming XML to HTML. In Figure 6a is shown the XSL stylesheet for transforming an XML document to an HTML document. This stylesheet is also generated automatically from XMLSchema through an XSLT by using the algorithm. In the following sections we will test the XSL stylesheet (generator). 

Finally, the resulting XSL stylesheets (generators) can then be used to generate SQL statements from an XML document or for transforming any XML document to HTML document. In the following sections we will introduce some examples to show how the generator works.     

                                                                 
                                 Figure 6a: Generic XSL stylesheet generated of the algorithm

4.2 How the Generator Works  

There are two examples in this section, for testing the generated XSL stylesheets shown in Figure 7 and 8 respectively. The first example for transforming XML to SQL statements is shown in Figure 7. While the second example shown in Figure 8 for transforming an XML document into an HTML document.

•	Transforming XML to SQL                     cllctn_id, cllctn_number, title, publis_date,
To illustrate how the generic XSL stylesheet shown in Figure 6 works, consider the example shown in Figure 7 for transforming an XML document to SQL. Let us walk through the example shown in Figure 7 by using the inputs (XSL stylesheet and XML document). The XML document has <collection> as an XML document root element contains the elements (child nodes) such as cllctn_id, cllctn_number, title, publis_date, remote, features, description, url, exh_exb_id, inst_inst_id and staf_staf_id. Then the XSL stylesheet templates matched with the root element of XML document and mapped the root node to the SQL table as table name (collection). Also the XSL stylesheet templates match the child elements and attribute elements in XML document and maps these as column names to an SQL table such as 

remote, features, description, url, exh_exb_id, inst_inst_id and staf_staf_id.    
Furthermore, the data values are mapped to SQL tables as data value to the corresponding column names such as (10,20,”collector”, “08.01.03”, “yes”, “exhibition”, “research”, “this is first exhibition”, “http//:www.virtualexh.com”,100,200,300). When the stylesheet is applied to an XML document, it produces a SQL statement as shown in Figure 7.
   Finally, we can conclude that, by using JDBC and connect XML/SQL, we can extract such XML data programmatically (Java) [McLaughlin 2001] by using the XSL stylesheet shown in Figure 6 to generate an SQL statement as a string, which is then stored in a relational database [Kossmann 99]. 

      Figure 7:  An example for transforming XML document to SQL

•	
•	Transforming XML to HTML
Basically, the HTML combines data and presentation in the web. Furthermore, the HTML is the only language understood by all browsers. The HTML provides a fixed set of predefined elements (or tags) that tell the browsers how to format and display information (or data) on the Web. Since XML considers only the data, we need to convert it into HTML, in order to display and present it on the Webs.
   Let us follow the example shown in Figure 8 by using the XML document, HTML document and the generated XSL stylesheet. An XSLT contains templates and commands to select and manipulate the structure of the data. It operates by reading a stylesheet, which consists of one or more templates, then matching the templates as it visits the nodes of

the XML document, pulls in data from an XML document and places it, with formatting, into an HTML document. For example, the root node is compared with all template rules in the stylesheet. It matches the first one, the <html> tag is written out and using <xsl:apply-templates> element to process the child of the root node, the <body> tag is also written out. All the child elements of object1 in XML are transformed to the body of an HTML document as objId 100, objNumber 1234, name altarpiece, title lasmeninas, regdate 12.01.98. Also the object2 is mapped as shown in the Figure 8,  the </body> tag is written out and the </html> tag is written. Figure 8 shows the transforming of XML to HTML in more details. 

Figure 8: Transforming XML to HTML by using a generated XSL Stylesheet

5 THE XQUERY INTERPRETER  
   GENERATION
Basically, the XQuery [W3C 2003, W3C 2004] is a language containing one or more query expressions. XQuery supports conditional expressions, element constructors, FOR, LET, WHERE, RETURN (FLWR) 

expressions, expressions involving operators and function calls and quantifiers, type checking, and path expressions. Some XQuery expressions evaluate to simple node values such as elements and attributes or atomic values such as strings and numbers. The syntax for retrieving, filtering, and transforming records uses FOR, LET, WHERE, RETURN clauses. A FLWR expression creates some bindings, applies a predicate, and produces a result set. XQuery does not conform to the same conventions as SQL. XQuery and SQL share some similar concepts. Both languages provide keywords for projection and transformation operations (SQL SELECT or XQuery RETURN). SQL supports joins between tables, and XQuery supports joins between multiple documents. Here are two simple examples one with XPath type of a 
query and the other with FLWR expression. The single forward slash (/) signifies the parent-child relationship between elements. In tracing a path through a tree the expression starts at the root node and follows parent node and so on.
1) X / <collection>/<object>/<objectInfor>
2) For obj in <collection> do
    Where obj = <object> 
    Return <object>
Furthermore we develop a simplified version of XQuery and the XQuery model based on the existing standard W3C XML Query to handle information of the XML documents. 
Finally in this section we introduce an algorithm for generating an XSL stylesheet from the XMLSchema to interpret the XQuery. In other words, this is the technology solution to the problem of generating automatically the XQuery interpreter by transforming an XMLSchema through an XSLT. The algorithm in Figure 9 shows how we can generate the XSL stylesheet, which can then be used for transforming XQueries to SQL queries as shown in Table 1.

                              Figure 9: Algorithm for generating XSL to transform XQueries to SQL queries 

// Input XMLSchema, XSL stylesheet
 // Output  XSL stylesheet  (Generic XSL stylesheet)
1.	start
2.	if the input arguments (XMLSchema, XSL stylesheet) exist
       2.1 Build DOM and parse it
       2.2 if parsing XMLSchema is done, then DOM will build dynamically
             2.2.1 perform XSL stylesheet transformation
             2.2.2 if transformation is done
                     2.2.2.1 the XSL templates start from the root node of DOM tree
                     2.2.2.2 If root node has parent/child node 
                          2.2.2.2.1 the XSL stylesheet template will walk and matches nodes, if the 
                                      template match IN node in DOM tree nodes 
      2.2.2.2.2 the XSL template adds FROM clauses as new template and 
                     maps the root node of DOM tree to the generated template in  
                     the new XSL stylesheet.      
                                2.2.2.2.3 the XSL stylesheet template pulls the nodes from DOM tree 
                                               and places them with formatting, into a new XSL stylesheet  
                          2.2.2.2.4 the XSL stylesheet template walks through the DOM tree nodes
                                        and when the template matches RETURN clauses
                          2.2.2.2.5 add the SELECT clauses to the template followed by the name
                                         of parent/child of DOM as new template to output
                          2.2.2.2.6 Iterate and walk through the DOM tree nodes 
                          2.2.2.2.7 if the XSL stylesheet template matches nodes has WHERE or 
                                         IF or ELSE, set the WHERE clauses as new template into the 
                                         new XSL stylesheet 
                                2.2.2.2.8 When all the templates have been executed and placed in the 
                                               output, then the new templates will be a generic XSL stylesheet 
                                               generated
                     2.2.2.3 report no parent/child node and terminate 
             2.2.3 report transformation errors and terminate
       2.3 report parsing errors and terminate
  3.  report arguments error and terminate
 4. terminate/end         

 

5.1 How the Algorithm Works 

In this section we will use the simplicity test, ratter than a formal one for testing the algorithm shown in Figure 9. Let us walk through the algorithm by using the XSL stylesheet and XMLSchema as input data for testing the algorithm. The algorithm is invoked with the start point of the algorithm by checking that the arguments exist (inputs of the algorithm). If they exist then parsing and “Building DOM” is done. If the parsing result is executed (line 3.2 in Figure 9) the DOM tree will build dynamically. If the transformation is done, (line 3.2.1 in Figure 9), the XSL stylesheet templates matched the root node in DOM tree is mapped as template to the new XSL stylesheet. Then if the root node has child nodes the XSL stylesheet will walk through the DOM tree, parent node and child nodes and iterate through the nodes, and map using them as templates in the output. 
The XSL stylesheet pulls nodes from DOM tree and places them, with formatting, to output as new templates to the new XSL stylesheet. 
The output of the algorithm will be a generic XSL stylesheet for transforming XQueries to SQL queries. Figure 10 shows the generated XSL stylesheet as output, from implementing the algorithm by using the XMLSchema and XSL stylesheet as input.

                          Figure 10: Generic XSL stylesheet for transforming XQueries to SQL queries

5.2 Testing the Generator (XSL) 
Table 1 illustrate some examples of XQueries transformed to SQL queries by using generic XSL shown in Figure 10. Table 1 has two columns, one for the XQueries and the second for the SQL queries generated as a result of 
using the generator (XSL stylesheet). In fact these examples show not just how the 

generator works, but also that the generator is generic, which means it is valid for transforming any XML query to an SQL query. Table 1 shows transforming of some complex XQueries examples 1, 2, 3, 4, 5 and 7 to corresponding SQL queries by using the XSL stylesheet shown in Figure 10 and also transforming simple XQuery to a corresponding SQL query as shown in example 6. 

                  Table 1: Transforming XQueries to SQL queries by using generated XSL Stylesheet
No.	           XQuery	       SQL Query	
1	For obj in <collection> do
Where coll = <cllctn_id> 
Return <cllctn_id><cllctn_num><name><title>	Select cllctn, cllctn_num, name, title
From collection
Where coll.clltn_id=clltn_id	
2	For obj in <collection>/<object>do
If obj=<obj_id> and obj=<cllctn_id> then
   Return <obj_id><obj_number><name><title>
else ()	Select obj_id, obj_number, name, title
Where obj.obj_id=obj.cllctn_id
From collection, object	
3	Let inf=<object>/<information>do
Where inf/<Info_id> = inf/<obj_id> 
Return <Inf>	Select *
From object, information
Where inf.Info_id = inf.obj_id	
4	For inst in <institution> do 
Return <inst>	Select *
From institution	
5	For obj in <collection>do
Return <object>	Select object
From collection	
6	X/<collection>/<object>	Select * From collection X	
7	Let coll=<collection> do
For obj in <object>
Where coll/<cllctn_id> = obj/obj_id>
Return<obj>	Select *
From collection, object
Where coll.clltn_id and obj.obj_id	

6 CONCLUSION
As a result of our work, the XSL stylesheet does not only transform XML to HTML or another format but also an XSL stylesheet can be used to generate an XSL from XMLSchema. Furthermore the XSL stylesheet transformation provides the suitable generic solution for transforming XMLSchema. The contribution of this work is that it introduces general techniques for generating SQL schema, XSL and XQuery using XMLSchema and XSL stylesheet, which (a) enables the use of these techniques for transforming XML data to SQL data and storing it in a relational database, (b) allows the user to present HTML format, and (c) interrupting XQueries, which means transforming XQueries to SQL queries so then we can retrieve and query data from the database. A potential cause for concern is that our general techniques may be less overlapping in implementing the technique is efficiency. However based on our prototype implementation in java, we have found that is very quick to generate XSL stylesheets as interpreter for different types of transformation such as SQL Schema and XQueries in to SQL queries. As we know it is possible to code by hand an XSL stylesheet that validates an XML document against some or all constraints of an XML schema and to generate an XSL stylesheet. However with our technique this task is easy, quick and less overlapping and we will use these generated components to integrate the (offline and online) components to satisfy our requirements. Also, we plan to extend these techniques to work with Multi XMLSchema not just single XMLSchema.

7 REFERENCES
A. Aboulnaga, Jeffrey F. Naughton, Chun Zhang. 
    Generating Synthetic Complex-Structured XML 
    Data. Fourth International Workshop on the 
    Web and Databases (WebDB'2001). Bar
Braganholo, Vanessa; Heuser, Carlos. Updating 
    Relational Databases through XML Views.  
    Technical Report RP-328. UFRGS, Porto 
    Alegre, RS, Brazil, 2002. 61 pages.
 Bourret R. XML and Database. Published 
    online at URL. http://www.rpbourret.com/xml/
    XMLAndDatabases.htm. 
 Bourret R. Mapping W3C Schemas to Object 
    Schemas to Relational Schemas. March 2001.
    www.rpbourret.com/xml/SchemaMap.htm
Chawathe S. “Describing and Manipulating XML  
     Data”, Bulletin of the IEEE Technical.   
DeHaan D, D. Toman, M. Consens, and M. T. 
    Özsu, "A Comprehensive XQuery to SQL 
    Translation using Dynamic Interval Encoding," In 
    Proceedings of ACM International Conference on 
    Management of Data (SIGMOD'03), San Diego, 
    June 2003, pages 623-634.
Florescu D., D. Koaamann. “Storing and Querying 
     XML Data using an RDBMS”, IEEE Data
     Engineering Bulletin, 22(3):27-34.  Sept. 1999.    
Kossmann F. and D. Kossmann. “A Performance 
    Evaluation of Alternative Mapping Schemes for 
    Storing XML Data in a Relational Database”. In  
    Rapport de Recherché No. 3684, INRIA,  
    Rocquencourt, France, March 1999.
Krishnamurthy R., Venkatesan T.Chakaravarthy, 
    Raghav Kaushik, Jeffrey F. Naughton.  
     Recursive XML Schemas, Recursive  
     XML Queries, and Relational Storage: XML-to- 
     SQL Query Translation: ICDE 2004.
 McLaughlin Brett (brett@newinstance.com). Java 
      and XML, 2nd edition, O’Reilly &  Associates, 
      Inc., August 2001, ISBN: 0-596- 00197-5.
Manolescu I., D. Florescu, D. Kossman. 
     “Answering XML Queries over Heterogeneous 
     Data Sources”. 27th VLDB Conference, pp. 241- 
     250, Rome, Italy, September 2001.
Norton Francis. Generating XSL for Schema 
    validation. May 20, 1999.    
    http://www.redrice.com/ci/generatingXslValid
Peterson David, Paul V. Biron, and Ashok Malhotra  
     XML Schema 1.1 Part 2: Datatypes. World Wide 
     Web Consortium, Working Draft WD- 
     xmlschema11-2-20040716, July 2004.
Shanmugasundaram J., E. Shekita, J. Kiernan, R.  
    Krishnamurthy, E. Viglas, J. Naughton and Igor  
    Tatarinov. A General Technique for Querying 
    XML Documents using a Relational Database 
    System. ACM SIGMOD Record, 30(3), 2001.
Sushant Jain, Ratul Mahajan, Dan Suciu.
    "Translating XSLT Programs to Efficient SQL 
    Queries" in the 11th  WWW Conference, 2002. 
W3C, Document Object Model (DOM) Level 2   
       HTML Specification Version 1.0 W3C 
      Recommendation 09 January 2003. 
      http://www.w3.org/TR/2003/REC-DOM-Level-  
      2-HTML-20030109.
William W. Provost. An XML Validation 
    Architecture Using XML Schema, XPath, and 
    XSLT.  February 2002.
W3C. Extensible Stylesheet Language (XSL) 
     Version 1.0, W3C Candidate Recommendation. 
     October 15, 2001.  
    http://www.w3.org/TR/2001/REC-xsl-20011015/  
W3C XSL Working Group, W3C Recommendation 
      on XSL Transformations (XSLT) version 1.0 
      (http://www.w3.org/TR/xslt). 1999.  
W3C.  XQuery 1.0: An XML Query Language, 
      W3C Working Draft May 02, 2003  
       http://www.w3.org/TR/2003/WD-xquery
W3C, 2000. “Extensible Markup Language (XML)   
       1.0 (second Edition)”, W3C Recommendation,  
       http://www.w3c.org/TR/REC-xml.
W3C. XQuery 1.0: An XML Query Language, 
       W3C Working Draft July 23, 2004.
W3C. W3C DOM Working Group. Document 
       Object Model. Published online at URL  
       http://www.w3.org/DOM/. (2004).
W3C. XQuery 1.0 and XPath 2.0 Data Model.  
      Working Draft July 23, 2004. Latest version 
      URL: http://www.w3.org/TR/xpath-datamodel/ 
Wang Yuan et al, 2002. X-Diff: A fast change 
      detection algorithm for XML documents. 
     University of Wisconsin-Madison, USA.