Top Banner
PublishingontheWeb usingXSL MaxFroumentin, W3C Page2002 7February2002 http://www.w3.org/People/maxf/talks/2002-02-XSL/talk.pdf
46

Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Aug 05, 2018

Download

Documents

dangtruc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Publishing on the Webusing XSL

Max Froumentin, W3CPage 20027 February 2002

http://www.w3.org/People/maxf/talks/2002-02-XSL/talk.pdf

Page 2: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

I. HTML and XML1. HTML2. XML

II. Styling and XML3. Style Sheets4. CSS5. Shortcomings of CSS

III. XSLT and XSL-FO6. The XSL Process7. The XSL syntax8. Two specifications9. XSLT10. Formatting Objects11. Example

IV. XSL on the Web12. Principle13. Pre-generation14. Dynamic generation15. In-browser XSLT16. Example17. Example II (MathML)18. The MathML Stylesheet

V. Advanced Usage19. Conversion20. Programming21. Example

VI. The Future22. XSLT 2.0

Page 3: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

23. XSL 2.024. Conclusion

Page 4: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

1. HTML and XML

Page 5: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

HTML is the language of the Web: text with a set oftags to mark headers, paragraphs, etc.

<html><h1>Title of the document</h1><p>This is the <i>text</i> ofthe document</p>

</html>

l h1: level 1 heading (title)

l p: paragraph

l i: italics, etc.

HTML and XML: HTML

Max Froumentin, W3C 1 of 24

Page 6: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

XML generalises HTML: one can define a languagewith any tag.

<conference><name>Page2002</name><date day="6-8" month="2" year="2002"/><location>Ikebukuro</location><abstract>This conference is about...</abstract></conference>

In order to specify how to display the document (onpaper, on the Web, etc.) it is necessary to apply styleto it.

HTML and XML: XML

Max Froumentin, W3C 2 of 24

Page 7: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

2. Styling and XML

Page 8: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Style sheets are useful for:

l Specifying the presentation of XML/HTMLdocuments (e.g. make all headers red)

l Separating presentation from content (separatefiles, simpler to maintain)

l in particular to allow users to alter the look ofWeb pages they receive.

l Allowing devices to render Web pages as bestthey can.

Two ways to create style sheets: CSS and XSL

Styling and XML: Style Sheets

Max Froumentin, W3C 3 of 24

Page 9: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Example: press releaseCSS uses a simple syntax:

body {background-color: #ddd;font-size: 200%;

}a { color: green; }h1 { color: red; }

Styling and XML: CSS

Max Froumentin, W3C 4 of 24

Page 10: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

People concerned with styling needed more:

l Content generation: indexes, table of contents.More generally, allow the author to write as littleas possible

l Complex formatting properties: pagination, I18N,etc. which CSS2 does not have.

XSL was designed to solve that. But it became muchmore...

Styling and XML: Shortcomings of CSS

Max Froumentin, W3C 5 of 24

Page 11: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

3. XSLT and XSL-FO

Page 12: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Whereas CSS does this:

XSLT and XSL-FO: The XSL Process

Max Froumentin, W3C 6 of 24

Page 13: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

XSL is designed to operate as:

XSLT and XSL-FO: The XSL Process

Max Froumentin, W3C 6 of 24

Page 14: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

FO is an XML vocabulary, with presentationsemantics. It defines:

l Tags such as <block>, <inline>,<page-sequence>, <footnote>

l Attributes such as text-indent, writing-mode, color(many borrowed from CSS)<block text-indent="30pt"writing-mode="rl-tb">

l A pagination model and area model to specifythe placement on pages

XSLT and XSL-FO: The XSL Process

Max Froumentin, W3C 6 of 24

Page 15: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

A stylesheet is a set of templates:

<xsl:template match="body"><page-sequence background-color="#ddd"

font-size="200%"><xsl:apply-templates/>

</page-sequence></xsl:template>

But there are many more constructs that CSS rulesdo not have, like programming language statements:loops, conditions, etc. Stylesheets can become quitecomplex.

XSLT and XSL-FO: The XSL syntax

Max Froumentin, W3C 7 of 24

Page 16: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

The XSL spec is split to reflect this process:

l Transformations: anyXML-to-FO

l Rendering: how to render Formatting Objects

The Great Idea was to make the XSL transformationsmore general: anyXML-to-anyOtherXML and to makeit to a separate specification: XSLT.

XSLT and XSL-FO: Two specifications

Max Froumentin, W3C 8 of 24

Page 17: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

l XSLT thus became a generic transformationlanguage that is now very popular (in particular totransform custom XML documents into HTML forpresentation in a browser).

l The rest of this talk will show examples of theuse of XSLT.

XSLT and XSL-FO: XSLT

Max Froumentin, W3C 9 of 24

Page 18: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

l Formatting Objects serve XSL's original purposeof advanced pagination and is more and moreused for technical documentation. The XSL 1.0Recommendation defines how to render the FOvocabulary.

l We will not go deeper into FOs since they will bedetailed in the next presentation, but an examplefollows.

XSLT and XSL-FO: Formatting Objects

Max Froumentin, W3C 10 of 24

Page 19: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

XSLideMakerThis set of slides was generated using XSL.

l source document: XHTML edited using Amaya,with figures in SVG and PNG.

l How the source document is displayed whenedited is not important since an XSL stylesheetwill "style" it to its final form.

l stylesheet that generates FO+SVG file,converted to PDF.

This shows a way to use XSL "off-line", withoutnecessarily publishing them on the Web

XSLT and XSL-FO: Example

Max Froumentin, W3C 11 of 24

Page 20: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

4. XSL on the Web

Page 21: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

With XSLT, it is possible to use XSL for publishingany kind of XML data to different sorts of devices(computers, phones, PDAs) that can display one type

XSL on the Web: Principle

Max Froumentin, W3C 12 of 24

Page 22: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

of XML presentation language (HTML, WML, FO).Several scenarios exist for performing thetransformation: pre-generation, on-demandtransformation and browser-side.

XSL on the Web: Principle

Max Froumentin, W3C 12 of 24

Page 23: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

From one XML source, a set of stylesheets generatedocuments in various formats at different URLs:

http://www.example.org/news.htmlhttp://www.example.org/news.svghttp://www.example.org/news.wml

Benefits:

l Standard stylesheet benefit: once stylesheets arewritten just the XML content needs to change

l Allows for simple client that knows only oneformat (SVG, WML, etc.)

XSL on the Web: Pre-generation

Max Froumentin, W3C 13 of 24

Page 24: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

l Can also generate different versions forsame-format, like

http://www.example.org/news-big.html

Example: The XSL page at W3C

l One XML source

l A set of stylesheets (XML to XHTML, XML toRSS, etc.)

The XHTML stylesheet performs complex operations:grouping, sorting, etc.

XSL on the Web: Pre-generation

Max Froumentin, W3C 13 of 24

Page 25: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Drawback of the static approach: that many uselesspages could be generated. Also, different URL forversion.

XSL on the Web: Pre-generation

Max Froumentin, W3C 13 of 24

Page 26: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

If client specifies a way to send its preferences, theserver can generate the correct version as asked.

l Content negociation: using HTTP Acceptheaders, the client can specify what format itprefers

Accept: application/svg+xhtmlGET http://www.w3.org/news

l CC/PP: many other parameters: screen size,colour preferences, localisation, device speed,etc.

XSL on the Web: Dynamic generation

Max Froumentin, W3C 14 of 24

Page 27: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Advantages:

l one URL for every version of the page(http://www.w3.org/news)

l more parameters can: different styles for eachformat (colors, size, etc.)

Drawbacks:

l High demand on server (simultaneous requests)

XSL on the Web: Dynamic generation

Max Froumentin, W3C 14 of 24

Page 28: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

More and more Web browsers can perform XSLTtransforms.

l The transformation can be done in the browser:thta is how it was meant to be from the start, butuntil it was actually possible (implemented),people used a few of the other methods.

l The language and stylesheets are the same asabove

l Server load decreased

l Client preferences can be processed locally

XSL on the Web: In-browser XSLT

Max Froumentin, W3C 15 of 24

Page 29: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

XSLT in browsers is becoming more and morepopular:

l to do XML to HTML: IE, Mozilla

l to do XML to FO: Antenna House's XMLFormatter, X-smiles

XSL on the Web: In-browser XSLT

Max Froumentin, W3C 15 of 24

Page 30: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

X-smiles: a Java Web browser for PCs and smalldevices.Does in-browser XSLT and renders:

l HTML, Xforms

l Formatting Objects

l SMIL, SVG, etc.

XSL on the Web: Example

Max Froumentin, W3C 16 of 24

Page 31: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

XSL on the Web: Example

Max Froumentin, W3C 16 of 24

Page 32: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

XSLT to display formulas in many browsers, usingMathML:

<math><msup><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow><mrow>2</mrow></msup></math>

Few browsers understand MathML , but XSLT gives asolution...

XSL on the Web: Example II (MathML)

Max Froumentin, W3C 17 of 24

Page 33: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Using XSLT in a HTML document, one can displayMathML in most popular browsers

<?xml-stylesheet href="mml.xsl"><html>...<math>...</math>...</html>

l Amaya: no XSLT, direct rendering

l Mozilla: XSLT does nothing, direct rendering

XSL on the Web: The MathML Stylesheet

Max Froumentin, W3C 18 of 24

Page 34: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

l IE5.5, IE6:

- If a MathML plug-in is installed, the stylesheet callsit (according to the user's preferences)

- If no MathML plug-in is installed, an approximaterendering using tables and CSS is performed

This does not work with browsers that do not supportXSLT or MathML.

XSL on the Web: The MathML Stylesheet

Max Froumentin, W3C 18 of 24

Page 35: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

XSL on the Web: The MathML Stylesheet

Max Froumentin, W3C 18 of 24

Page 36: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

5. Advanced Usage

Page 37: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

XSLT has been found useful for other uses, such as:

l MathML to SVG,

l HTML to RSS (w3.org), etc.

l XML document validation or serialisation

Advanced Usage: Conversion

Max Froumentin, W3C 19 of 24

Page 38: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

l Including variables in other languages:<xsl:variable> and <xsl:value-of> allowimplementation of general expressions withvariables in an XML file. e.g. geometricconstraints in SVG.

<svg ...><xsl:variable name="start_x" select="10"/><rect x="$start_x * 2" y="40".../><circle x="$startx_x + 24" y="20".../>

</svg>

Advanced Usage: Programming

Max Froumentin, W3C 20 of 24

Page 39: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

l An XML programming language?

- XSLT was not meant to be one, so it would besimple to use.

- But people do crazy things with it, like generating afile from no output. This is not easy (since numberiterations) are hard to implement, but people do it!

Advanced Usage: Programming

Max Froumentin, W3C 20 of 24

Page 40: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Chess stylesheet

l ChessGML to SVG+SMIL animation

l This is a rather complex style sheet that turns aChessGML file to an SVG animation of theboard.

ChessGML:

<mp> <!-- 4. Kf1 b5 --><m c="w"><p c="w" n="k"/><e1/><f1/></m><m c="b"><p c="b" n="p"/><b7/><b5/></m>

</mp>

Advanced Usage: Example

Max Froumentin, W3C 21 of 24

Page 41: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

SVG:

<!-- move 4 --><animateTransform attributeName="transform" attributeType="XML" type="translate" from="0,0" to="0,-4.5" accumulate="sum" additive="sum" begin="move3.end" dur="1s" restart="never" fill="freeze" xlink:href="#moveList"/><animate id="move4" begin="move3.end" xlink:href="#F" attributeName="x" attributeType="XML" dur="2s" from="55" to="25" fill="freeze" restart="never"/><animate xlink:href="#F" attributeName="y" attributeType="XML" begin="move3.end" dur="2s" from="78.5" to="48.5" fill="freeze" restart="never"/>

Advanced Usage: Example

Max Froumentin, W3C 21 of 24

Page 42: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

Advanced Usage: Example

Max Froumentin, W3C 21 of 24

Page 43: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

6. The Future

Page 44: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

The first Working Draft has been published:

l a more powerful language

l Designed in conjunction with XML Query

l designed for more complex use for XMLdatabases.

The Future: XSLT 2.0

Max Froumentin, W3C 22 of 24

Page 45: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

There are plans for a new version of XSL with:

l More formatting objects and properties

l Generalised areas, flow control

l Compatibility with CSS3

The Future: XSL 2.0

Max Froumentin, W3C 23 of 24

Page 46: Publishing on the Web using XSL - World Wide Web … · Publishing on the Web using XSL Max Froumentin, W3C ... FO is an XML vocabulary, ... edited is not important since an XSL stylesheet

l XSL is a simple yet powerful solution to docontent management on the Web

l It is fully XML, allowing manipulation of all newW3C file formats: FO, SVG, MathML.

l May be confusing for programmers at first(different programming style), but worth trying!

l Very popular: many implementations and uses.

The Future: Conclusion

Max Froumentin, W3C 24 of 24