Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 5.21 5.2 Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute.

Similar presentations


Presentation on theme: "Lecture 5.21 5.2 Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute."— Presentation transcript:

1 Lecture 5.21 5.2 Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute Toronto, ON

2 Lecture 5.22 Outline Introduction to Apache Xalan. Use the Xalan interactive processor from the command line. Use the Xalan Java API to apply an XSLT transformation. Use the JSP Standard Tag Library to apply transformations

3 Lecture 5.23 Apache Xalan Fully compliant XSLT 1.0 processor Fully supports XPath 1.0 Includes an Interpretive processor for debugging. Can be configured to work with any W3C compliant XML parser. Optimized for Xerces. Can process stream, SAX, or DOM input. Can output to a stream, SAX, or DOM

4 Lecture 5.24 Apache Xalan Transformations may be chained. Includes an applet wrapper. May be used in a servlet May be used from JavaServer Pages. Can be extended.

5 Lecture 5.25 Outline Introduction to Apache Xalan. Use the Xalan interactive processor from the command line. Use the Xalan Java API to apply an XSLT transformation. Use the JSP Standard Tag Library to apply transformations

6 Lecture 5.26 Applying transformation from the command line Use the interpretive processor for simple command line based transformations. Advantages: –Easier to debug by isolating transformation from a larger more complex system. –Can see output of to console. is used for debugging. Similar to System.out.println(). –Quick to execute –Simple to use

7 Lecture 5.27 Applying transformations from the command line

8 Lecture 5.28 Outline Introduction to Apache Xalan. Use the Xalan interactive processor from the command line. Use the Xalan Java API to apply an XSLT transformation. Use the JSP Standard Tag Library to apply transformations

9 Lecture 5.29 Using the Java API Prerequisites –Must include necessary JAR files in your classpath such as xalan.jar, and an XML parser such as Apache Xerces. –An XML document to transform, either from a file, W3C DOM structure, or string. –A valid XSLT Stylesheet which describes the rules of transformation.

10 Lecture 5.210 Using the Java API - Example This program takes in an XML filename, and an XSLT filename, and writes the result of the transformation to standard output. The first step is to get the argument values and convert them to URIs (Uniform Resource Identifiers). The second step involves creating a TransformerFactory object. This object employs the factory pattern. The third step is to create a Transformer object for the XSLT stylesheet. The fourth step is to transform the XML document.

11 Lecture 5.211 Using the Java API - Example

12 Lecture 5.212 Using the Java API - Example

13 Lecture 5.213 Outline Introduction to Apache Xalan. Use the Xalan interactive processor from the command line. Use the Xalan Java API to apply an XSLT transformation. Use the JSP Standard Tag Library to apply transformations

14 Lecture 5.214 Using Xalan from JavaServer Pages The common pattern for doing XSLT transformation in Java Server Pages (JSP) is to use the JSP Standard Template Library. It is also possible to import the Xalan classes and embed Java code using the API.

15 Lecture 5.215 Introduction to JSTL JavaServer Pages Standard Tag Library (JSTL) encapsulates common JSP functionality into Tags. JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and tags for accessing databases using SQL. It also introduces the concept of an expression language to simplify page development.

16 Lecture 5.216 JSTL & XML

17 Lecture 5.217 Core Tags Provides the basic functionality for accessing and parsing XML data. The parse tag parses an XML file and stores the result in a type of variable. The expr and set tags are for running XPath expressions. set can store the results into a scoped JSP attribute.

18 Lecture 5.218 Flow Control Tags Similar to XSLT. Allows for evaluating XPath expressions and creating control statements. for-each allows for iterating over a node-set.

19 Lecture 5.219 Transformation Tags Perform XSLT transformations! Optionally pass parameters to the stylesheet such as external information only known as runtime.

20 Lecture 5.220 Using Xalan from JavaServer Pages There’s some setup required! There are multiple ways of doing this, use what works. This technology is very new. You must import the tag library definitions. The files must then be mapped in web.xml The supporting JAR files must be in your web application’s classpath (usually WEB-INF/lib).

21 Lecture 5.221 Using Xalan from JavaServer Pages

22 Lecture 5.222 Using Xalan from JavaServer Pages

23 Lecture 5.223 Parsing an XML document Must read in the XML as a string using the core tag import. Use the parse tag on this string variable to parse into a DOM structure.

24 Lecture 5.224 Parsing an XML document Parse XML Parse XML demo

25 Lecture 5.225 Using XPath in JSTL XPath Demo XPath demo

26 Lecture 5.226 Using XPath in JSTL

27 Lecture 5.227 Running a Transformation from JSTL Similar to the previous example, reading the XML file from disk is done with the import tag. The transform tag is used to transform the XML using the XSLT that must also be read in and parsed

28 Lecture 5.228 Running a Transformation from JSTL

29 Lecture 5.229 Running a Transformation from JSTL

30 Lecture 5.230 Expression Language (EL) JSP 2.0 introduced Expression Language (EL). EL is used extensively in JSTL. EL expressions are found in the special holder ${ }. Attributes can be accessed through EL. –Example: ${pageContext.request.method} could be equal to ‘GET’ or ‘POST’

31 Lecture 5.231 LAB Section The purpose of this lab is to get a working knowledge of using xalan in the three methods described. –Command Line –Java API –JSP/JSTL All Code and examples have been provided

32 Lecture 5.232 The Data The Data chosen for this lab is the XML output from apollo: the sequence annotation tool. Apollo is a collaboration between the Drosophila Genome Project, the Sanger Institute and the EBI. GMOD has adopted Apollo for sequence annotation. The XML output generated is GameXML.

33 Lecture 5.233 Apollo

34 Lecture 5.234 The Source Use CVS to checkout the gamexml module. It includes the following –A build.xml file for ant –2 GameXML files (game.xml, smallgame.xml) –2 XSLT stylesheets (game_transcript.xsl, game_sequence.xsl) –game.dtd (no XML Schema available) –MyTansformer

35 Lecture 5.235 Exercises 1.Explore the project 2.Run MyTransformer with an XML file and a XSLT Stylesheet. 3.Install the Web Application into tomcat. 4.Run all the JSPs and see how they work. 5.Write your own JSP with JSTL tags for processing XML.


Download ppt "Lecture 5.21 5.2 Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute."

Similar presentations


Ads by Google