Building Dynamic Forms with XML, XSLT

Similar documents
<?xml version = 1.0 encoding= windows-874?> <?xml-stylesheet type= text/css href= #xmldocs?> <style id= xmldocs > element-name{ } </style>

Web Programming Paper Solution (Chapter wise)

XSL Languages. Adding styles to HTML elements are simple. Telling a browser to display an element in a special font or color, is easy with CSS.

AJAX. Introduction. AJAX: Asynchronous JavaScript and XML

WHITE PAPER. Query XML Data Directly from SQL Server Abstract. DilMad Enterprises, Inc. Whitepaper Page 1 of 32

AJAX and PHP AJAX. Christian Wenz,

Ajax- XMLHttpResponse. Returns a value such as ArrayBuffer, Blob, Document, JavaScript object, or a DOMString, based on the value of

CITS1231 Web Technologies. Ajax and Web 2.0 Turning clunky website into interactive mashups

The main Topics in this lecture are:

Exam : Title : XML 1.1 and Related Technologies. Version : DEMO

Use of PHP for DB Connection. Middle and Information Tier. Middle and Information Tier

XMLHttpRequest. CS144: Web Applications

XML. Objectives. Duration. Audience. Pre-Requisites

Birkbeck (University of London)

Proof Of Concept: XSLTProcessor extension

Use of PHP for DB Connection. Middle and Information Tier

A.A. 2008/09. What is Ajax?

2/6/2012. Rich Internet Applications. What is Ajax? Defining AJAX. Asynchronous JavaScript and XML Term coined in 2005 by Jesse James Garrett

XSLT: How Do We Use It?

XML and XSLT. XML and XSLT 10 February

Pure JavaScript Client

Using XML and RDBMS Data Sources in XPages Paul T. Calhoun NetNotes Solutions Unlimited, Inc

Computer Science E-259

INLS 760 Web Databases Lecture 12 XML, XPATH, XSLT

Programming the World Wide Web by Robert W. Sebesta

Web Application Security

Implementing XForms using interactive XSLT 3.0

A Web-based XML Schema Visualizer José Paulo Leal & Ricardo Queirós CRACS INESCPORTO LA

COP 4814 Florida International University Kip Irvine XSLT. Updated: 2/9/2016 Based on Goldberg, Chapter 2. Irvine COP 4814

Style Sheet A. Bellaachia Page: 22

XML: Extensible Markup Language

Lesson 12: JavaScript and AJAX

Credits: Some of the slides are based on material adapted from

Introduction to InfoSec SQLI & XSS (R10+11) Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)

AJAX: The Basics CISC 282 March 25, 2014

Delivery Options: Attend face-to-face in the classroom or via remote-live attendance.

Languages in WEB. E-Business Technologies. Summer Semester Submitted to. Prof. Dr. Eduard Heindl. Prepared by

AJAX(Asynchronous Javascript + XML) Creating client-side dynamic Web pages

HTML. HTML: logical structure

CS6501 IP Unit IV Page 1

EXAM XML 1.1 and Related Technologies TYPE: DEMO

Manipulating XML Trees XPath and XSLT. CS 431 February 18, 2008 Carl Lagoze Cornell University

Oracle Application Server 10g Oracle XML Developer s Kit Frequently Asked Questions September, 2005

Delivery Options: Attend face-to-face in the classroom or remote-live attendance.

7.1 Introduction. extensible Markup Language Developed from SGML A meta-markup language Deficiencies of HTML and SGML

,

XML Processing & Web Services. Husni Husni.trunojoyo.ac.id

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 7 XML


Sample Relational Database Modern Information Systems

Author: Irena Holubová Lecturer: Martin Svoboda

INTERNET & WEB APPLICATION DEVELOPMENT SWE 444. Fall Semester (081) Module 4 (III): XSL

Enhancing WebGen5 with Access Control, AJAX Support, and Editable-and-Insertable Select Form.

Section A: Multiple Choice


COPYRIGHTED MATERIAL. Contents. Part I: Introduction 1. Chapter 1: What Is XML? 3. Chapter 2: Well-Formed XML 23. Acknowledgments

Generating Variants Using XSLT Tutorial

Extensions to XSLT 1.0, and XSLT 2.0

Presentation 19: XML technologies part 2: XSL, XSLT, XSL-FO, XPath & XML Programming

AFew existing languages transforming XML data into

XSLT (part I) Mario Alviano A.Y. 2017/2018. University of Calabria, Italy 1 / 22

XSL Elements. xsl:copy-of

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2018)

/ Introduction to XML

Dynamic Indexing with XSL

Burrows & Langford Appendix D page 1 Learning Programming Using VISUAL BASIC.NET

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

8/1/2016. XSL stands for EXtensible Stylesheet Language. CSS = Style Sheets for HTML XSL = Style Sheets for XML. XSL consists of four parts:

AJAX: The Basics CISC 282 November 22, 2017

XSL Concepts: Conditions and Loops. Robert Kiffe, Senior Web Developer OmniUpdate, Inc.

Applied Databases. Sebastian Maneth. Lecture 18 XPath and XSLT. University of Edinburgh - March 23rd, 2017


Extensible Markup Stylesheet Transformation (XSLT)

E-Applications. XML and DOM in Javascript. Michail Lampis

XML APIs Testing Using Advance Data Driven Techniques (ADDT) Shakil Ahmad August 15, 2003

AJAX เสถ ยร ห นตา ส าน กเทคโนโลย สารสนเทศและการส อสาร มหาว ทยาล ยนเรศวร พะเยา

x ide xml Integrated Development Environment Specifications Document 1 Project Description 2 Specifi fications

A Mathematical Theorematic Approach to. Computer Programming

Term Paper. P r o f. D r. E d u a r d H e i n d l. H o c h s c h u l e F u r t w a n g e n U n i v e r s i t y. P r e s e n t e d T o :

Introduction to XSLT. Version 1.0 July nikos dimitrakas

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

XML Extensible Markup Language

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

2010 Martin v. Löwis. Data-centric XML. Other Schema Languages

Generating Web Pages Using XSLT

define.xml: A Crash Course Frank DiIorio

Display the XML Files for Disclosure to Public by Using User-defined XSL Zhiping Yan, BeiGene, Beijing, China Huadan Li, BeiGene, Beijing, China

Creating an Online Catalogue Search for CD Collection with AJAX, XML, and PHP Using a Relational Database Server on WAMP/LAMP Server

Microsoft ASP.NET Whole Course Syllabus upto Developer Module (Including all three module Primary.NET + Advance Course Techniques+ Developer Tricks)

XML. COSC Dr. Ramon Lawrence. An attribute is a name-value pair declared inside an element. Comments. Page 3. COSC Dr.

10.1 Overview of Ajax

An Introduction to AJAX. By : I. Moamin Abughazaleh

User Interaction: jquery

Advanced XSLT. Web Data Management and Distribution. Serge Abiteboul Ioana Manolescu Philippe Rigaux Marie-Christine Rousset Pierre Senellart

BPM Multi Line Container in Integration Process

CSI 3140 WWW Structures, Techniques and Standards. Representing Web Data: XML

XML and Databases. Lecture 11 XSLT Stylesheets and Transforms. Sebastian Maneth NICTA and UNSW

AJAX: Introduction CISC 282 November 27, 2018

4. Unit: Transforming XML with XSLT

COMP9321 Web Application Engineering

Transcription:

International Journal of Computing and Optimization Vol. 2, 2015, no. 1, 23-34 HIKARI Ltd, www.m-hikari.com http://dx.doi.org/10.12988/ijco.2015.517 Building Dynamic Forms with XML, XSLT Dhori Terpo University E. Çabej, Faculty of Natural Sciences, Department of Mathematics & Informatics, Gjirokastra, Albania Endrit Xhina University of Tirana, Faculty of Natural Sciences, Department of Informatics, Tirana, Albania Copyright 2015 Dhori Terpo and Endrit Xhina. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited. Abstract Data entry forms are a key component of all process automation applications. This paper will present an approach for building dynamic data entry forms using data that have been stored in a relational database. By following a series of steps, we transform these data into a dynamic HTML form using the web technologies XML and XSLT. This approach reduces the amount of software development time and maintenance required to generate and process such forms and can have very high payoff in many enterprise process automation applications. Keywords: Data Entry Form, HTML, XML, XSLT 1 The need for dynamic forms Data entry forms are a key component of all process automation applications. In current applications, most of the content of a data entry form is created during the phase of its development. When the requirements of an application are changed, this leads to redesign or recompile the form s file. Furthermore, because different processes have different data inputs, the design of a preliminary data entry form for generalization, is impossible. To overcome these limitations in the creation of data entry forms, we suggest a general approach for building dynamically the content s elements of a data entry form, by converting them from a database, being stored, into HTML form.

24 Dhori Terpo and Endrit Xhina 2 Proposed Solution Our suggestion for creating dynamically the content s elements of a form is presented by the following steps: 1. Save the data that represent form s elements and user s inputs of a process dynamically into database. 2. Export the data of a use case of a process as XML. 3. Convert the XML data through XSLT into HTML Form. 4. Use the browser s events for sending to a server the changed value of an input. 5. Modify the input s value into the database. These steps are presented in a diagram in Figure 1. MSSQL SERVER FOR XML XSLT Browser events Server-side script Store the inputs in tables Export the case data in XML Transform XML into HTML Form Send request for modification of input's value Catch the request and save the value into database Figure 1. The steps followed for building a dynamic data entry form 3 Database Schema In Figure 2, is presented our database schema, used for saving dynamically the elements of a form and the user s input data that are collected via the form. The table Process, stores data about the process we are configuring, the table Cases, stores data about a use case of a process, the table Inputs, stores data about elements of a form and the table Data stores user s input data for a use case.

Building dynamic forms with XML, XSLT 25 Figure 2. Database schema of our approach 4 Converting SQL data to XML The FOR XML clause extends a SELECT statement by allowing return of data from relational tables into an XML structured document. The basic syntax [1] of the FOR XML clause is as follows: FOR XML RAW [( <element> )] [<directives>] [ELEMENTS] AUTO [<directives>] [ELEMENTS] EXPLICIT [<directives>] PATH [( <element> )] [<directives>] [ELEMENTS] <directives> = [, TYPE ] [, ROOT ( <root> ) ] The FOR XML clause syntax can be described as follows: RAW: Returns a single XML element for each record returned by a query. Thus a join returns an element for each record returned by the join, regardless of the number of tables in the join query. All fields become attributes with each recordelement produced. AUTO: A nested structure is created when there is more than one table in the query. Thus, for join queries, a nested structure of XML elements is returned. In other words, each table in the query returns a single layer of nested elements. Additionally, the order of fields in the selected list helps to determine XML document structure.

26 Dhori Terpo and Endrit Xhina EXPLICIT: This mode allows the most flexibility but also more complex queries. However, explicit definition allows for explicit definition of an XML element hierarchical structure. ( <element> ): Allows for an element name change. ELEMENTS: Fields are returned as child elements as opposed to attribute name-value pairs. <directives>: Some of these are the TYPE and ROOT directives: o TYPE: A query or subquery will return a string typecasted into a SQL Server XML data type. o ROOT: Adds a top layer root element to XML document output, creating a properly structured XML document. Not specifying a name creates the root element as <root>. PATH: Allows more simplistic and comprehensive query construction than the EXPLICIT clause. Other options are as follows: o XMLDATA: Returns an XML-Data Reduced (XDR) schema. o XMLSCHEMA: Returns an XSD schema. o BINARY BASE64: Returns binary data. In Listing 1, we retrieve the process case data as XML by specifying the FOR XML clause in the query. Listing 1 - Converting SQL data to XML <?php $servername = "servername\instancename"; $connectioninfo = array( "Database"=>"databasename"); $conn = sqlsrv_connect( $servername, $connectioninfo); $sql="select dbo.inputs.inputid as [id], dbo.inputs.type as [type], dbo.inputs.name as [name], dbo.data.value as [value] from dbo.inputs inner join dbo.data on dbo.inputs.inputid=dbo.data.inputid where dbo.data.caseid= $_REQUEST[caseId] FOR XML PATH('element'),ROOT('elements'), ELEMENTS XSINIL,TYPE"; $stmt = sqlsrv_query( $conn, $sql); sqlsrv_fetch($stmt);

Building dynamic forms with XML, XSLT 27 $xml=' '; $xml.='<?xml version="1.0" encoding="utf-8"?>'; $xml.=sqlsrv_get_field($stmt,0,sqlsrv_phptype_string('utf-8')); $file = 'form.xml'; file_put_contents($file, $xml); sqlsrv_free_stmt( $stmt); sqlsrv_close($conn);?> 5 Converting XML to HTML through XSLT XML it s a text-based format that you can use to hold data on different platforms and in different kinds of applications. But just because some information is held in XML doesn t mean that it s immediately useful. You still need to write a program to manipulate the data. One of the most common things that you ll want to do with XML is to present that information as HTML pages on the Web, as PDF documents for printing, as text for emailing, and so on. The W3C [2] started developing a standard language for presenting information held in XML in 1998. This language was named the Extensible Stylesheet Language (XSL). Extensible Stylesheet Language Transformation [3], or XSLT, is a straightforward language that allows you to transform existing XML documents into new XML, Hypertext Markup Language (HTML), Extensible Hypertext Markup Language (XHTML), or plain text documents. XML Path language, or XPath, is a companion technology to XSLT that helps identify and find nodes in XML documentselements, attributes, and other structures. XSLT defines many elements to describe the transformations that should be applied to a document. For details on XSLT element and functions read the W3C XSL Transformations [4]. In Figure 3, is presented the transformation of a XML file (as shown in Listing 2) through XSL file (as shown in Listing 3) in a web browser. Listing 2 - The XML file form.xml <?xml version="1.0" encoding="utf-8"?> <elements xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <element> <id>1</id> <type>text</type> <name>first Name</name> <value/> </element> <element> <id>2</id>

28 Dhori Terpo and Endrit Xhina <type>text</type> <name>last Name</name> <value/> </element> <element> <id>3</id> <type>date</type> <name>date of Birth</name> <value/> </element> <element><id>4</id> <type>text</type> <name>city</name> <value/> </element> </elements> Listing 3 - The XSL file form.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <table> <xsl:for-each select="elements/element"> <tr> <xsl:if test="type='text'"> <td> <xsl:value-of select="name"/> : </td> <td> <input type="text" id ="id" size="20" onchange="myfunction(this.id,this.value)" /> </td> </xsl:if> <xsl:if test="type='date'"> <td> <xsl:value-of select="name"/> : </td> <td> <input type="date" id ="id" size="20" onchange="myfunction(this.id,this.value)" /> </td> </xsl:if> </tr> </xsl:for-each>

Building dynamic forms with XML, XSLT 29 </table> </xsl:template> </xsl:stylesheet> Figure 3. XML to HTML transformation through XSLT 6 Dynamic Transformations of XML content through XSLT Dynamic transformations of XML content can take place in two locations server side or client side. Server-side transformations are run on the server in response to the client s request for a particular page. Client-side transformations are run on the client when it receives a particular page. 6.1 Server-Side Transformations With server-side transformations [5], the client makes a single request for a page, and the server returns a single page to the client. When the server receives a request, it identifies the XML that holds the data for the page to use and what XSLT stylesheet to use with it. The server then performs the transformation and returns the result of the transformation to the client. This process is illustrated in Figure 4. Figure 4. Server-side transformations Many different server-side languages are capable of working with XML applications. Common languages include VB.NET, C#.NET, PHP, ColdFusion,

30 Dhori Terpo and Endrit Xhina JavaServer Pages (JSP), and Perl. Listing 4 shows how to load and transform an XML document using PHP. This example uses the form.xml (as shown in Listing 2) and XSLT stylesheet form.xsl (as shown in Listing 3). Listing 4 - Transforming an XML document using PHP <?php // Load XSL file $xsl = new DomDocument(); $xsl->load("form.xsl"); // Load XML file $xml = new DomDocument(); $xml->load("form.xml"); // Configure the transformer $proc = new XsltProcessor(); //Applies the transformation and shows the results $xsl = $proc->importstylesheet($xsl); $newdom = $proc->transformtodoc($xml); print $newdom->savexml();?> 6.2 Client-Side Transformations With client-side transformations [6], the page that the client requests from the server includes instructions that tell the client how to transform the XML. The client performs the transformation, and displays the results. This process is illustrated in Figure 5. Figure 5. Client-side transformations

Building dynamic forms with XML, XSLT 31 Listing 5 shows how to transform a XML document on the client using Asynchronous JavaScript and XML (Ajax). This example uses the form.xml (as shown in Listing 2) and XSLT stylesheet form.xsl (as shown in Listing 3). Listing 5 - Transforming an XML document using Ajax <html> <head> <script> function loadxmldoc(filename) if (window.activexobject) xhttp = new ActiveXObject("Msxml2.XMLHTTP"); else xhttp = new XMLHttpRequest(); xhttp.open("get", filename, false); try xhttp.responsetype = "msxml-document" catch(err) xhttp.send(""); return xhttp.responsexml; function displayresult() xml = loadxmldoc("form.xml"); xsl = loadxmldoc("form.xsl"); // code for IE if (window.activexobject xhttp.responsetype == "msxml-document") ex = xml.transformnode(xsl); document.getelementbyid("1").innerhtml = ex; // code for Chrome, Firefox, Opera, etc. else if (document.implementation && document.implementation.createdocument) xsltprocessor = new XSLTProcessor(); xsltprocessor.importstylesheet(xsl); resultdocument = xsltprocessor.transformtofragment(xml, document); document.getelementbyid("1").appendchild(resultdocument);

32 Dhori Terpo and Endrit Xhina </script> </head> <body onload='displayresult()'> <form name='registrationform'> <div id="1" /> </form> </body> </html> Building applications with Ajax provides all of the advantages of working clientside with XML content. The application caches the interface and makes asynchronous requests for data. The user isn t waiting for pages to load from the server. 7 Editing the content of the form The HTML source code of the form in Figure 3 shows that every form s element has an onchange event. This event, handles a javascript function (as shown in Listing 6) that creates an AJAX XMLHttpRequest object and sends a request to the server side script edit.php (as shown in Listing 7) that updates the records of the table Data. In this way we collect all the user s inputs data of the form and write them into database. Listing 6 - Javascript function that handles the onchange event <script> function myfunction(id,value) var xmlhttp; if (window.xmlhttprequest) // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); else // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); var querystring ="?id="+id+"&value="+value+"&caseid="+ "<?php echo $_REQUEST['caseId'];?>"; xmlhttp.open("get","edit.php"+querystring,true); xmlhttp.send(null); </script>

Building dynamic forms with XML, XSLT 33 Listing 7 - The server side script edit.php <?php $servername = " servername\instancename "; $connectioninfo = array( "Database"=>"databasename"); $conn = sqlsrv_connect( $servername, $connectioninfo); $id=$_get['id']; $value=$_get['value']; $caseid=$_get['caseid']; $sql="update dbo.data SET value ='$value' WHERE caseid =$caseid AND inputid ='$id'"; $stmt = sqlsrv_query( $conn, $sql); sqlsrv_free_stmt( $stmt1);?> 8 Conclusions This paper briefly discusses an approach for building dynamic data entry forms. We indicate how by following a series of steps, using technologies like XML and XSLT, we can transform data stored in relational database into HTML form and render this form in a web browser. This approach reduces the amount of software development time and maintenance required to generate and process such forms and can have very high payoff in many enterprise process automation applications. References [1] G. Powell, Beginning XML Databases, Wiley Publishing, Inc. 2007. [2] World Wide Web Consortium available at http://www.w3.org/. [3] M. Fitzgerald, Learning XSLT, O'Reilly Media, Inc., 2003. [4] XSL Transformations Version 2.0 available at http://www.w3.org/tr/xslt20/ [5] J. Tennison, Beginning XSLT 2.0: From Novice to Professional, Apress 2005. http://dx.doi.org/10.1007/978-1-4302-0046-8

34 Dhori Terpo and Endrit Xhina [6] S. Jacobs, Beginning XML with DOM and Ajax: From Novice to Professional, Apress 2006. http://dx.doi.org/10.1007/978-1-4302-0177-9 Received: February 5, 2015; Published: March 6, 2015