g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates”...

23
1 1 Extreme Java G22.3033-007 Session 3 - Sub-Topic 5 XML Information Rendering Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences 2 Agenda Extensible Stylesheet Language Transformation (XSL-T) Extensible Stylesheet Language Formatting Object (XSL-FO) XML and Document/Content Management XML/XSL and JSP/JavaBeans Rendering Technology Internationalization Issues Web Content Accessibility Guidelines (WCAG)

Transcript of g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates”...

Page 1: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

1

1

Extreme JavaG22.3033-007

Session 3 - Sub-Topic 5XML Information Rendering

Dr. Jean-Claude Franchitti

New York UniversityComputer Science Department

Courant Institute of Mathematical Sciences

2

Agenda

Extensible Stylesheet Language Transformation (XSL-T)Extensible Stylesheet Language Formatting Object (XSL-FO)XML and Document/Content ManagementXML/XSL and JSP/JavaBeans Rendering TechnologyInternationalization IssuesWeb Content Accessibility Guidelines (WCAG)

Page 2: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

2

3

XML-Based Rendering DevelopmentXML Software Development Methodology

Language + Stepwise Process + ToolsRational Unified Process (RUP) v.s. “XML Unified Process”

XML Application Development InfrastructureMetadata 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’sXSL Formatter, HTML/CSS1/2/3, XHTML, XForms, WCAG

XML Applications Involved in the Rendering Phase:Application(s) of XMLXML-based applications/services (markup language mediators)

MOM, POP, Other Services (e.g., persistence)

Application Infrastructure Frameworks

4

XML Data Rendering Patterns

Manipulating and Rendering XML Structures UsingJava

XSL-TTransformSortOutput

XSL-T + -FOFormatOutput

Querying will be covered separately

Page 3: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

3

5

What is XSL?

XSL is a language for expressing stylesheets. It consists oftwo parts:

A language for transforming XML documentsA XML vocabulary for specifying formatting semanticsSee http://www.w3.org/Style/XSL for the XSLT 1.0/XPath 1.0Recs, the XSL-FO 1.0 candidate rec, and working drafts ofXSLT 1.1/2.0 and XPath 2.0

A XSL stylesheet specifies the presentation of a class of XMLdocuments. It describes how an instance of the class istransformed into an XML document that uses the formattingvocabulary

6

eXtensible Style Language (XSL)DSSSL & DSSSL-OCSS 1, 2, 3 …

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

XSLTXPathXSL-FOXSLT Processors

Stylus Studio XSL development environmentIBM XSL EditorSaxon and Xalan XSLT processors

XSL-FO ProcessorsAntenna Housefop

Page 4: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

4

7

XSL Processinghttp://www.w3.org/Style/XSL/Processing Alternatives:

HTML + CSS -> PresentationXML + CSS -> PresentationXML + XSLT -> XSL-FO -> PresentationXML + XSLT -> XML/HTML + CSS -> Presentation

Client or Server Processing ?See Session 2 handout on IE5’s implementation of the XSL Spec.

ExamplesSee Session 2 Sub-Topic 1 Presentation: Beginning XMLSee Session 2 handouts on XSL Tree Transformation LanguageSee Session 2 handout on Cascading StylesheetsSee Session 2 handout on Styling Documents Using XSL

8

A Language for “Mapping XML”(LMX)

LMX is a sample textbook applicationLMX can convert a document in one DTD into another DTD andvice versaLMX uses rules to describe bi-directional “MOM” conversionsbetween two sets of documents

Rules have a “from-pattern” and a “to-pattern”b to respectively matchthe source document, and construct the target documentSome restrictions exist w.r.t. the LMX patterns in order to simplify theprogram as much as possible

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

Page 5: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

5

9

How Does the LMX Processor Work?

LMX makes heavy use of the DOM 1.0 APILMX uses XML4J internally to:

Parse a rule fileParse a source documentGenerate a target document

See chapter 4.3 in the XML and Java textbook for a detaileddescription of the LMX implementation

10

LMX v.s. the eXtensible StylesheetLanguage (XSL)

LMX and XSL both provide a syntax to encode “StyleSheets”Each XML document can be associated with a style sheetthat describes how elements should be organized andformatted for presentationXSL style sheets provide custom appearances that give aweb site a unified look and feel

Page 6: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

6

11

How Does XSL Work?

A XSL style sheet is an XML documentXSL elements in a XSL style sheet correspond to a seriesof XSL “transformation” rules (i.e., XML treetransformation and/or formatting rules)XSL rules describe how particular XML tags are to beconverted to “flow objects” as the document is read

12

Part I

Extensible Stylesheet Language Transformation(XSLT)

Page 7: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

7

13

XSL Transformations

Assume root element of style sheet is <xsl>Each <xsl> element contains one or more rule elementsEach rule has a target and an actionTarget is a regular expression defining to which XML elements therule appliesAction 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 theelementActions may output XML tags obtained via transformation of original XMLdataActions may output non-markup text, or run simple scripts or programsActions may use JavaScript to provide more complex, and dynamic behaviors

14

XSL Transformations (continued)

Conceptual Representation of XSL Transformations: <xsl> <rule> <target-element type=“tagname”/> action </rule> <rule> (…) </rule> </xsl>

Page 8: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

8

15

XSL-T and Templates

XSLT rules are also called “Templates”There may not be rules to match every elementElements can be reordered on the output.XSL style sheet must be well-formed

e.g., a HTML empty tag specified as <br> must be written as<br/> within a XSL style sheet action

XSLT elements used as a basis for a simple stylesheetare:

<xsl:stylesheet>, <xsl:template match …>, <xsl:apply-templates>, <xsl:for-each select ...>, and <xsl:sort select …>

16

XSLT Elements and FunctionsCreating Elements and Attributes

xsl:element, xsl:attributeIteration and Sorting (e.g., xsl:sort)Conditional Processing

xsl:apply-templates select=“ … “, xsl:if, xsl:chooseCopying Nodes (e.g., xsl:copy)Combining Stylesheets

xsl:import, xsl:includeDefining Variables & Parameters (e.g., xsl:variable)Scripting with XPath functions

Page 9: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

9

17

Parsers with XSLT Support

SAX 2.0 or DOM Level 2 1.0 Support RequiredApache’s Xalan XSLT parser

org.apache.xalan.processor/templates/transformerorg.apache.xpath

Saxon XSLT parserJAXP 1.1 (javax.xml.transform)

TraXPSupported by Xalan 2.0, and Saxon 6.1

Sun’s XSLTCConverts stylesheet’s to class files (“translets”)

18

Part II

Extensible Stylesheet LanguageFormatting Object (XSL-FO)

Page 10: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

10

19

XSL Formatting

XSL flow objects are markup textMarkup language output flow objects can be HTML,DSSSL, VRML, etc.We will focus on HTML output flow objects (simpler,more widely understood, better supported by current tools,and do not require an extra level of translation)

20

XSL Formatting Characteristics

XSL formatting is simpler than DSSSL (Document StyleSemantics and Specification Language, pronounced “dissal”,ISO std 10179:1996)XSL formatting is more powerful than CSS (Cascading StyleSheets)XSL’s basic formatting syntax is understandable by anybodyacquainted with DSSSL or CSS

Page 11: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

11

21

Part III

XML and Document/Content Management

22

What is a XSL Processor?

A XML document and its associated style sheet arecombined by an XSL processor to produce a HTMLdocument

The XSL Processor applies the style sheet to the XML documentand outputs static HTMLThe process can be automated with CGI scripts, Java servlets, orActiveX controls to convert XML to HTML on the fly

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

Page 12: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

12

23

How Does a XSL Processor Work?

The XSL processor consults the style sheet to find the rulethat matches the elementThe XSL processor takes whatever action is associated tothe rule:

outputs element’s content plus assorted markupperforms more complicated operations (sorting XML data beforeoutputting it, running a Javascript program on the XML data,adding missing content to XML data, etc.)

24

How Does a XSL Processor Work?(continued)

XSL processor formats each element upon receiptXSL processor may process elements recursivelyXSL processor receives input from XML processor andoutputs formatted data based on the nature of the elements itreceives

E.g., XSL processor receives <strong> elementXSL processor may output same content as bold textIf processor is an audio renderer, it may pump up the volume a notch...2

Page 13: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

13

25

How Does a XSL Processor Work?

The XSL processor consults the style sheetto find the rule that matches the elementThe XSL processor takes whatever action isassociated to the rule:

outputs element’s content plus assorted markupperforms more complicated operations (sorting XMLdata before outputting it, running a Javascript programon the XML data, adding missing content to XML data,etc.)

26

How Does a XSL Processor Work?(continued)

XSL processor formats each element upon receiptXSL processor may process elements recursivelyXSL processor receives input from XML processorand outputs formatted data based on the nature ofthe elements it receives

E.g., XSL processor receives <strong> elementXSL processor may output same content as bold textIf processor is an audio renderer, it may pump up the volume a notch...

Page 14: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

14

27

Mainstream XSL Processors

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

See IBM’s LotusXSL, Apache’s xalan, and fop.Look at Appendix E of the class textbook forrelevant information on XSLA comprehensive list of XSL formatters, andXSLT engines/editors/utilities is available athttp//www.xmlsoftware.com

Includes links to latest product pagesIncludes Version numbers, Licensing information,and Platform details

28

DOM 1.0 XSL Processing Support

The DOM Level 1 specification does not support XSLstylesheetsMicrosoft’s initial version of MSXML DOM includeda DOM Level 1 extension that added support for XSLstylesheets

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

Similar extensions were emulated early on by otherXSL processors (LotusXSL, xalan, fop, etc.)DOM Level 2 1.0 formalizes rendering support

Page 15: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

15

29

Mainstream XSL Processors

See Microsoft’s XML and XSL Samples and Demos athttp://msdn.microsoft.com/xmlSee IBM’s LotusXSL, Apache’s xalan, and fop. Look atAppendix E of the class textbook for relevant informationon XSLA comprehensive list of XSL formatters, and XSLTengines/editors/utilities is available athttp//www.xmlsoftware.com

Includes links to latest product pagesIncludes Version numbers, Licensing information, andPlatform details

30

Xalan

Xalan-J version 2.1.0 is the latestProvides XSL-T processing for transformingXML documents into HTML, text, or otherXML document typesBuilt on top of SAX 2.0, DOM Level 2 1.0,JAXP 1.1Implements the TraX subset of JAXP 1.1

Page 16: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

16

31

FOP

Latest version is 0.19xml.apache.org/fop, www.jtauber.com

Print formatter driven by XSL-FO objectsFormatted output is in PDF format for nowCan be embedded in a Java application byinstantiating org.apache.fop.apps.Driver

32

Frameworks

Cocoon 2XangBatik

Page 17: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

17

33

Part IV

XML Application Servicesand

XML Rendering Technology

34

Towards XML Application ServiceProcessing

DOM ExtensionsBinding ExtensionsComponent Frameworks (reusable component models)Model-Based Automation (MDA)

RenderingDOM 2.1.0, SAX 2.0, JAXP 1.1 & TraX, XSL-FO 1.0Component Frameworks

QueryingXQuery 1.0, XSLT 1.1/2.0, XPath 1.0/2.0

Security (signatures encryption/decryption, etc.)Etc.

Page 18: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

18

35

Rendering Software DevelopmentLanguages (XSL)Process (“XUP”)Frameworks (POP/MOM) - See XMLJ2EE

Cocoon 2.0XangBatikEtc.

XSL InfrastructureXSL-T Processors: Saxon 6.1, Xalan-J 2.1.0XSL-FO Processors: fop 0.19

36

W3C’s New “Architecture” Slant

New W3C UI Domain StructureDocument Formats

AmayaGraphicsInternationalizationMathStyle

InteroperationDevice independenceSMIL and voice browsers

Architecture

Page 19: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

19

37

Part V

XML Internationalization Issues

38

W3C InternationalizationInternationalization Activity Statement

http://www.w3.org/International/Activity.htmlI18N and L10N features incorporated in (X)HTML, CSS, XML,RDF, SMIL, DOM, MathML, SVG, XPath, XSL(T), and XMLSchema, HTTP 1.0W3C’s Jigsaw, Amaya

Problem is to document encodings being usedW3C Character Model

Character Model for the World Wide WebNormalization to Unicode Standard and ISO/IEC 10646

Ruby AnnotationUnicode in XML and other Markup Languages

Page 20: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

20

39

Part VI

Web Content Accessibility Guidelines(WCAG 1.0)

40

Current State of XML Standards

WCAG 1.0 (5/5/99) - W3C RecommendationWCAG 2.0 (3/28/01) - W3C Working Draft

Support wide range of languagesEasier to use by authoring tools developersEasier to check conformance

Techniques for WCAG 1.0 (3/20/00)

Page 21: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

21

41

Guidelines SummaryProvide Alternatives to Auditory and VisualcontentAvoid sole reliance on colorsUse markup and style sheetsClarify natural language usageCreate tables that transform wellMake Sure that Pages that Feature NewTechnologies Transform WellEnsure User Control of Time-SensitiveContent Changes

42

Guidelines Summary(continued)

Ensure Direct Accessibility of Embedded UIsDesign for Device IndependenceUse Interim SolutionsUse W3C Technologies and GuidelinesProvide Context and Orientation InformationProvide Clear Navigation MechanismsProvide Clear and Simple Documents

Page 22: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

22

43

Part VII

Conclusions

44

Summary

XSL style sheets describe how individual elementsare displayed in HTMLA XSL processor like LotusXSL converts anXML document and its associated style sheet intoan HTML document that can be read by currentweb browsersStyle instructions are stored in rule elements

Page 23: g22 3033 007 c36€¦ · 8 15 XSL-T and Templates QXSLT rules are also called “Templates” QThere may not be rules to match every element QElements can be reordered on the output.

23

45

Summary(continued)

Each rule has a pattern and an actionThe pattern define the elements to which the ruleappliesThe action specifies the flow objects that the XSLprocessor outputs when the rule fires

When multiple rules apply to one element, onlythe most specific rule is appliedFlow objects usually include the content of theelement, along with some combination of HTMLmarkup

46

Summary(continued)

XML Application Services support a stepwiseapproach towards the development of XML-basedsystem architecturesW3C Internationalization is moving towardsnormalization based on a web character modelI18N/L10N support needs to keep being addedinto XSL, and CSS3. XML Query, XMLProtocols, XForms, and newer XML technologiesContent Accessibility Guidelines are targeted toWeb and Authoring Tools developers to ensurethat Web content is accessible to people withdisabilities