XML for Java Developers G22.3033-002

Session 7 - Main Theme XML Information Rendering (Part I)

Dr. Jean-Claude Franchitti

New York University Computer Science Department Courant Institute of Mathematical Sciences

1

Agenda

„ Summary of Previous Session

„ Extensible Stylesheet Language Transformation (XSL-T)

„ Extensible Stylesheet Language Formatting Object (XSL-FO)

„ XML and Document/Content Management

„ Introduction to XML Application Servers

„ Working with XSLT-T and XSL-FO Processors

„ Assignment 4a+4b (due in two week)

2

1 Summary of Previous Session

„ Summary of Previous Session

„ (DOM)

„ Advanced XML Parser Technology

„ JDOM: Java-Centric API for XML

„ JAXP: Java API for XML Processing

„ Parsers comparison

„ Latest W3C APIs and Standards for Processing XML

„ XML Infoset, DOM Level 3, Canonical XML

„ XML Signatures, XBase, XInclude

„ XML Schema Adjuncts

„ Java-Based XML Data Processing Frameworks

„ Assignment #3 3

XML-Based Rendering Development

„ XML Software Development Methodology

„ Language + Stepwise Process + Tools

„ Rational Unified Process (RUP) vs. “XML Unified Process”

„ XML Application Development Infrastructure

„ Metadata Management (e.g., XMI)

„ XSLT, XPath XSL-FO APIs (JAXP, JAXB, JDOM, SAX, DOM)

„ XML Tools (e.g., XML Editors, Apache’s FOP, Antenna House’s XSL Formatter, HTML/CSS1/2/3, XHTML, XForms, WCAG

„ XML App. Components Involved in the Rendering Phase:

„ Application(s) of XML

„ XML-based applications/services ( mediators)

„ MOM, POP, Other Services (e.g., persistence) 4 „ Application Infrastructure Frameworks

2 Part I

Introduction to XSL

5

EXtensible Stylesheet (XSL) Language Family

„ Family of recommendations to define XML document transformation and presentation as “style sheets”

„ Three parts:

„ A language for transforming XML documents

„ XSL Transformations (XSLT)

„ Expression language used by XSLT to access or refer to parts of an XML document

„ XML Path Language (XPath) (also used for XML Linking)

„ A XML vocabulary for specifying formatting semantics

„ XSL Formatting Objects (XSL-FO)

„ See http://www.w3.org/Style/XSL for the XSLT 1.0, XPath 1.0, and XSL-FO 1.0 recommendations and

working drafts of XSLT 2.0 and XPath 2.0 6

3 How Does XSL Work?

„ An XSL style sheet is an XML document „ XSLT elements in an XSL style sheet correspond to a series of XSL “transformation” rules (i.e., XML tree transformation and/or formatting rules) „ XSLT rules describe how particular XML tags are to be converted to “flow objects” as the document is read „ XPath (e.g., para[@type="warning"][5])

„ http://www.w3.org/2002/11/xquery-xpath-applets/xpathApplet. 7

XSL Example

„ XML Document General Road Building noises. Come off it Mr Dent, you can't win you know. There's no point in lying down in the path of progress. I've gone off the idea of progress. It's overrated

8

4 XSL Example (continued)

„ Sample stylesheet :

9

XML Data Rendering Patterns

„ Manipulating and Rendering XML Structures Using Java

„ XSLT

„ Transform

„ Sort

„ Output

„ XSLT + XSL-FO

„ Format

„ Output

„ Querying will be covered separately

10

5 XSL Related Technologies

„ DSSSL & DSSSL-O

„ CSS 1, 2, 3 …

„ http://www.w3.org/Style/CSS/

„ XSLT

„ XPath

„ XSL-FO

„ XSLT Processors

„ Stylus Studio XSL development environment

„ IBM XSL Editor

„ Saxon and Xalan XSLT processors

„ XSL-FO Processors

„ Antenna House 11 „ fop

XSL Processing

„ See http://www.w3.org/Style/XSL/

„ Processing Alternatives:

„ HTML + CSS -> Presentation

„ XML + CSS -> Presentation

„ XML + XSLT -> XSL-FO -> Presentation

„ XML + XSLT -> XML/HTML + CSS -> Presentation

„ Client or Server Processing ?

„ See Session 2 handout on IE5’s implementation of the XSL Spec.

„ Examples

„ See Session 2 Sub-Topic 1 Presentation: Beginning XML

„ See Session 2 handouts on XSL Tree Transformation Language

„ See Session 2 handout on Cascading Stylesheets

„ See Session 2 handout on Styling Documents Using XSL 12

6 A Language for “Mapping XML” (LMX)

„ LMX is a sample textbook application st „ XML and Java texbook (1 edition)

„ LMX can convert a document in one DTD into another DTD and vice versa

„ LMX uses rules to describe bi-directional “MOM” conversions between two sets of documents

„ Rules have a “from-pattern” and a “to-pattern”b to respectively match the source document, and construct the target document

„ Some restrictions w.r.t. the LMX patterns in order to simplify the program as much as possible

„ LMX can also be used to convert a XML document to HTML (“POP” application) 13

How Does the LMX Processor Work?

„ LMX makes heavy use of the DOM 1.0 API

„ LMX uses XML4J internally to:

„ Parse a rule file

„ Parse a source document

„ Generate a target document

„ See chapter 4.3 in the XML and Java textbook (1st Edition) for a detailed description of the LMX implementation 14

7 LMX v.s. the eXtensible Stylesheet Language (XSL)

„ LMX and XSL both provide a syntax to encode “Style Sheets”

„ Each XML document can be associated with a style sheet that describes how elements should be organized and formatted for presentation

„ XSL style sheets provide custom appearances that give a web site a unified look and feel 15

Part II

Extensible Stylesheet Language Transformation (XSLT)

16

8 XSLT http://www.dpawson.co.uk/xsl/sect1/sect1.html

„ An XSLT stylesheet specifies the presentation of a class of XML documents

„ Describes how an instance of the class is transformed into an XML document that uses a formatting vocabulary (e.g., XHTML, XSL-FO)

„ XSLT Terminology

„ See http://www.dpawson.co.uk/xsl/xslvocab.html

„ Ref. card: http://www.mulberrytech.com/quickref/

„ “@”: abbreviation for attribute

„ “..”: abbreviation for parent::node()

„ “*”: identifies all of the element children of the context node (@* means all attributes)

„ “.”: abbreviation for self::node() 17

XSL Transformations

„ Assume root element of style sheet is

„ Each element contains one or more rule elements

„ Each rule has a target and an action

„ Target is a regular expression defining to which XML elements the rule applies

„ Action is the list of flow objects generated when the rule is applied:

„ Actions output a series of HTML tags in combination with the content of the element

„ Actions may output XML tags obtained via transformation of original XML data

„ Actions may output non-markup text, or run simple scripts or programs

„ Actions may use JavaScript to provide more complex, and dynamic behaviors 18

9 XSL Transformations (continued)

„ Conceptual Representation of XSL Transformations: action (…)

19

XSLT and Templates

„ XSLT rules are also called “Templates”

„ There may not be rules to match every element

„ Elements can be reordered on the output.

„ XSL style sheet must be well-formed

„ e.g., a HTML empty tag specified as
must be written as
within a XSL style sheet action

„ XSLT elements used as a basis for a simple stylesheet are:

„ , , , , and

20

10 XSLT Elements and Functions

„ Creating Elements and Attributes

„ xsl:element, xsl:attribute

„ Iteration and Sorting (e.g., xsl:sort)

„ Conditional Processing

„ xsl:apply-templates select=“ … “, xsl:if, xsl:choose

„ Copying Nodes (e.g., xsl:copy)

„ Combining Stylesheets

„ xsl:import, xsl:include

„ Defining Variables & Parameters (e.g., xsl:variable)

„ Scripting with XPath functions 21

Parsers with XSLT Support

„ SAX 2.0 or DOM Level 2 1.0 Support Required

„ Apache’s Xalan XSLT parser

„ org.apache.xalan.processor/templates/transformer

„ org.apache.

„ Saxon XSLT parser

„ JAXP 1.2 (javax..transform)

„ Transformation API for XML (TraX)

„ Supported by Xalan 2.5.1, and Saxon 6.3

„ Sun’s XSLTC (donated to Apache and used in Xalan)

„ Converts stylesheet’s to class files (“translets”) 22

11 XSLT APIs

23

XSLT API Packages

„ See Session 3 handout on “Processing XML Documents in Java Using XPath and XSLT”

„ javax.xml.transform

„ Defines the TransformerFactory and Transformer classes, which you use to get a object capable of doing transformations. After creating a transformer object, you invoke its transform() method, providing it with an input (source) and output (result).

„ javax.xml.transform.dom

„ Classes to create input (source) and output (result) objects from a DOM.

„ javax.xml.transform.sax

„ Classes to create input (source) from a SAX parser and output (result) objects from a SAX event handler.

„ javax.xml.transform.stream

„ Classes to create input (source) and output (result) objects from an I/O stream. 24

12 Using TraX http://www-106.ibm.com/developerworks/xml/library/x-tiptrax/

„ Create source, style, and result objects, and manipulate them using a “Transformer” object

„ Transformer can consume a stream of SAX events to avoid the use of intermediate files or other objects to hold data

„ See complete example using TraX at:

„ http://www.informit.com/isapi/product_id~%7B29A138BF-A72D- 4E3F-AA1C-596EAF7099BD%7D/content/index.asp

25

Part III

Extensible Stylesheet Language Formatting Object (XSL-FO)

26

13 XSL Formatting Pipeline

„ XSL-FO is an intermediate form (partial media-dependent output)

„ Java APIs: JAXP + FOP, jFO, XEP, etc.

„ http://www.xmlsoftware.com/xslfo.html 27

XSL Formatting

„ XSL flow objects are markup text

„ Markup language output flow objects can be HTML, DSSSL, VRML, etc.

„ Focus is usually on HTML output flow objects (simpler, more widely understood, better supported by current tools, and do not require an extra level of translation)

„ CSS vs. XSL-FO

„ CSS is an external stylesheet language

„ Styling properties are attached to selected elements in an XML or HTML document

„ XSL-FO completely describes a styled document (content organization, styling, layouts, layout-selection-rules, etc.) 28

14 XSL Formatting Characteristics

„ XSL formatting is simpler than DSSSL (Document Style Semantics and Specification Language, pronounced “dissal”, ISO std 10179:1996)

„ XSL formatting is more powerful than CSS (Cascading Style Sheets)

„ XSL-FO is not a “page-description” language, instead it allows the specification of layout rules (e.g., where page breaks occur)

„ XSL’s basic formatting syntax is understandable by anybody acquainted with DSSSL or CSS

„ XSL-FO design guidelines

„ XML Syntax

„ Declarative

„ Built on CSS

„ Cross-media 29 „ Multilingual support

Part IV

XML and Document/Content Management

30

15 What is a XSL Processor?

„ A XML document and its associated style sheet are combined by an XSL processor to produce a HTML document

„ The XSL Processor applies the style sheet to the XML document and outputs static HTML

„ The process can be automated with CGI scripts, Java servlets, or ActiveX controls to convert XML to HTML on the fly

„ A XSL processor is a standalone program or is part of a larger XML browser

31

How Does a XSL Processor Work?

„ The XSL processor consults the style sheet to find the rule that matches the element

„ The XSL processor takes whatever action is associated to the rule:

„ outputs element’s content plus assorted markup

„ performs more complicated operations (sorting XML data before outputting it, running a Javascript program on the XML data, adding missing content to XML data, etc.)

32

16 How Does a XSL Processor Work? (continued)

„ XSL processor formats each element upon receipt

„ XSL processor may process elements recursively

„ XSL processor receives input from XML processor and outputs formatted data based on the nature of the elements it receives

„ E.g., XSL processor receives element

„ XSL processor may output same content as bold text

„ If processor is an audio renderer, it may pump up the volume a notch...2

33

Mainstream XSL Processors

„ See Microsoft’s XML and XSL Samples and Demos at http://msdn.microsoft.com/xml

„ See IBM’s LotusXSL, Apache’s xalan, and fop. Look at Appendices of the class textbooks for relevant information on XSL

„ A comprehensive list of XSL formatters, and XSLT engines/editors/utilities is available at http//www.xmlsoftware.com

„ e.g., TEI’s PassiveTex, AntennaHouse XSL Formatter, RenderX’s XEP, Arbortext’s E3, Advent’s XSL-FO Renderer, Adobe’s Document Server, IBM’s Infoprint, etc.

„ Includes links to latest product pages

„ Includes Version numbers, Licensing information, and Platform details 34

17 DOM 1.0 XSL Processing Support

„ The DOM Level 1 specification does not support XSL stylesheets

„ Microsoft’s initial version of MSXML DOM included a DOM Level 1 extension that added support for XSL stylesheets

„ The function transformNode(…) was used to apply an XSL stylesheet to an existing XML document

„ Similar extensions were emulated early on by other XSL processors (LotusXSL, xalan, fop, etc.)

„ DOM Level 2 1.0 formalizes rendering support

35

Xalan

„ Xalan-J version 2.5.1 is the latest

„ Provides XSL-T processing for transforming XML documents into HTML, text, or other XML document types

„ Built on top of SAX 2.0, DOM Level 2 1.0, JAXP 1.1

„ Implements the TraX subset of JAXP 1.2

36

18 FOP

„ xml.apache.org/fop, www.jtauber.com

„ Print formatter driven by XSL-FO objects

„ Formatted output is in PDF format for now

„ Can be embedded in a Java application by instantiating org.apache.fop.apps.Driver

37

Part IV

XML Rendition Frameworks and Application Servers

38

19 Mainstream Frameworks

„ Cocoon 2

„ Xang

„ Batik

39

Rendition Architectural Patterns

„ Thin-Client

„ XML + XSL transformation

„ Thick-Client

„ (XML + XSL transformation) + applets/midlets

„ (XML + XSL transformation) + XML-driven renderers

40

20 Part V

Sample WAP/WML Platform

41

Introduction to WAP

• WAP is a standard for mobile Internet applications • Open standard for optimized access via a mobile device to the Internet or Intranet • WAP advances have been slowed down by limitations of mobile devices and mobile networks • Small screens • Limited device memory • Less powerful CPUs • Limited bandwidth availability • Unreliable connections • High latency 42

21 WAP Innerworkings

• Structure Content -> Rendition -> Presentation • Presentation Infrastructures: • HTML over HTTP + HTML Browser • WML over WAP + WAP Browser • WAP 1.x browser requires a WAP gateway • Gateway acts as intermediary between the mobile device and the Internet • WAP features • Security model similar to Web security • Simplistic development (WML and WMLScript) • Widely accepted

• Standards independent 43

WAP Architecture

44

22 WAP Architecture (continued)

45

WAP Programming Model

46

23 WAP Protocol Stack

47

Introduction to WML

• WML is a markup language based on XML • WML was developed by the WAP Forum • http://www.wapforum.org/ • WML is well-formed XML that adheres to predefined rules • Some WAP gateways can translate HTML to WML

48

24 WML vs. HTML

• WML was designed for wireless terminals with target screens a few lines long and about an inch wide • WML is case sensitive • All tags and attributes must be in lowercase • WML is unforgiving of incorrectly nested tags • WML does not assume that a “QWERTY” keyboard or a mouse is available for user input

49

WML Cards • Card specifies a single interaction between the user and the user agent • Multiple cards are grouped in decks • Deck is the topmost element of a WML document • Example:

My First WML Example

50

25 More WML Cards

Business
Education
Entertainment
Restaurants
Shopping
Travel
Weather

(…) 51

More WML Cards (continued)

(…)

Canadian
Chinese
Continental
French
German
Greek
Italian

52

26 Using Ericsson WapIDE (continued)

53

Loading First Card

54

27 WML Navigation

• WML Anchors Go to food • HTML tags Go to food • WML alternative 55

Graphics in WML

tag • Empty tag • Wireless bitmaps (.wbmp) are specially designed for wireless devices with a small monochrome screen • Use Paint Shop Pro to create .wbmp file via converter or plugin

56

28 WMLScript

• Based on ECMAScript (standard for JavaScript) • WMLScript is compiled into byte code before it is sent to the client (due to minimum memory and narrowband communication requirements) • Can be used to add script support to the client • E.g., user input validation, message and dialog generation, user agent facilities access such as making phone calls, access the SIM cars, or configure the user agent once deployed

57

WMLScript

• Based on ECMAScript (standard for JavaScript) • WMLScript is compiled into byte code before it is sent to the client (due to minimum memory and narrowband communication requirements) • Can be used to add script support to the client • E.g., user input validation, message and dialog generation, user agent facilities access such as making phone calls, access the SIM cars, or configure the user agent once deployed

58

29 WAP and Java Servlets import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * This is a simple servlet that will run on a cell-phone. It displays the * current date and time. */ public class MobileDate extends HttpServlet { public void service (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // set content type for wireless data response.setContentType("text/vnd.wap.wml"); // get the communication channel with the requesting client PrintWriter out = response.getWriter(); // write the data (…)

59

WAP and Java Servlets (continued)

(…) out.println(""); out.println(""); out.println(""); out.println(""); out.println("

"); out.println("Date and Time Service
"); out.println("Date is: "+ new java.util.Date()); out.println("

"); out.println(""); out.println(""); } }

60

30 WAP and Java Server Pages

"http://www.wapforum.org/DTD/wml_1.1.xml">

<%

response.setContentType("text/vnd.wap.wml"); out.println(""); out.println(""); out.println("

"); out.println("Date and Time Service
"); out.println("Date is: "+ new java.util.Date()); out.println("

"); out.println(""); out.println(""); %>

61

WAP Required MIME Types

• WML source files • text/vnd.wap.wml for .wml files • WML compiled files • application/vnd.wap.wmlc for .wmlc files • WMLScript source files • text/vnd.wap.wmlscript for .wmls files • WMLScript compiled files • application/vnd.wap.wmlscriptc for .wmlsc files • Wireless bitmaps • image/vnd.wap.wbmp for .wbmp files 62

31 WAP 2.0 Standards

• XHTML has been adopted as the basis for WAP 2.0 • XHTML Basic is the mobile version of XHTML 1.0 • WAP Forum based XHTML Mobile Profile on XHTML Basic • WAP CSS is the mobile version of cascading style sheets (CSS) • WAP 2.0 does not require a gateway • XHTML goes through in text format instead of

being binary encoded 63

Part VI

Conclusions

64

32 Summary

„ XSL style sheets describe how individual elements are displayed in HTML

„ A XSL processor like LotusXSL converts an XML document and its associated style sheet into an HTML document that can be read by current web browsers

„ Style instructions are stored in rule elements

65

Summary (continued)

„ Each rule has a pattern and an action

„ The pattern define the elements to which the rule applies

„ The action specifies the flow objects that the XSL processor outputs when the rule fires

„ When multiple rules apply to one element, only the most specific rule is applied

„ Flow objects usually include the content of the element, along with some combination of HTML markup

66

33 Readings

„ Readings

„ XML and Java: Chapters 7, 10, Appendices A and B

„ Processing XML with Java: Chapters 16-17, and Appendix C

„ Handouts posted on the course web site

„ Review WCAG status on W3C web site

„ Review XSL (XSLT, and XSL-FO) W3C Recommendations

„ Project Frameworks Setup (ongoing)

„ Apache’s Web Server, TomCat/JRun, and Cocoon

„ Apache’s Xerces, Xalan, Saxon

„ Antenna House XML Formatter, Apache’s FOP, X-smiles

„ Publishing Systems at http://www.xmlsoftware.com

„ Visibroker 4.5 (or BES 5.2), WebLogic 6.1-8.1, WAS 5.0

„ POSE & KVM (See Session 3 handout) 67

Assignment

„ Assignment #4:

„ This part of the project focuses on the application content model design/development using XML information rendering technology. The design/development process should adhere to the following steps: (a) Identifying rendering/transformation targets, (b) Defining the optimal rendering approach for each target, (c) Considering data rendering issues when designing an overall application data model

„ More specific project related information, and extra credit assignments will be provided during the session

68

34 Next Session: XML Information Rendering (Part II)

„ XML/XSL and JSP/JavaBeans Rendering Technology

„ Internationalization Issues

„ Web Content Accessibility Guidelines (WCAG)

„ Web Services

69

35