XML Technologies in action, XSLT/XPath/FO/MathML/SVG XML Technologies in action, XSLT/XPath/FO/MathML/SVG Contents Principles of XSLT Examples of usage: Various output formats server transforms vs. browser transforms XML Formats: standard XHTML XSLT and XML for Content Management

XSLT and XML for Content Management

... SVG Example arcs01 - arc commands in path data Picture of a pie chart with two pie wedges and a picture of a line with arc blips XML Formats: custom SCENE II. The same. Another street. Enter the corpse of KING HENRY the Sixth, Gentlemen with halberds to guard it; LADY ANNE being the mourner LADY ANNE Set down, set down your honourable load, If honour may be shrouded in a hearse, Whilst I awhile obsequiously lament The untimely fall of virtuous Lancaster. ... From one to the other In order to make data available on the Web, one can use HTML: CD stocks

CD stocks

ArtistTitlePriceIn-store
SupertrampEven in The Quietest Moments...12.99 EUR4
RunrigThe Big Wheel5.99 EUR12
QueenThe Miracle5.99 EUR1
ArtistTitlePriceIn-store SupertrampEven in The Quietest Moments...12.99 EUR4 RunrigThe Big Wheel5.99 EUR12 QueenThe Miracle5.99 EUR1 Or one can design custom XML markup CD stocks Supertramp Even in The Quietest Moments... 12.99 Runrig The Big Wheel 5.99 Queen The Miracle 5.99 Because, as the custom XML markup provides better information on what it describes it makes it easier to manipulate the data. And it's easier to read. HTML markup is attached to the way the documents is going to be displayed (table) and indeed makes it harder to process for other purposes. However HTML has the advantage that is displays on your browser. The custom markup can't be displayed as is. This is where stylesheets come into the picture. Here will describe one method of doing it: XSLT, a language to transform XML documents. Display your data using XSLT Uses: Transform custom XML into "displayable" XML More generally, transform anyXML into anyOtherXML XSLT works by defining templates. In our example, becomes <h3> Template:<xsl:template match="title"> <h3><xsl:apply-templates/></h3> </xsl:templates> Full recordML to HTML transform: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <html><xsl:apply-templates/></html> </xsl:template> <xsl:template match="inventory"> <head><xsl:copy-of select="title"/></head> <body><table><xsl:apply-templates/></table></body> </xsl:templates> <xsl:templates match="record"> <tr> <td><xsl:apply-templates select="artist"/></td> <td><xsl:apply-templates select="title"/></td> <td><xsl:apply-templates select="price"/></td> <td><xsl:apply-templates select="@in-store"/></td> </tr> </xsl:templates> <xsl:template match="price"> <xsl:value-of select="concat(.,' ',@unit)"/> </xsl:template> We will not go much further into the syntax of XSLT, as it is not really the point of this presentation. Rather we will concentrate on applications of XSLT. Many output formats XSLT allows any type of output markup in the stylesheet Example: record database record in database in XML and XSLT transforms, make it easy to process the database in different ways: Output the data: HTML (music2html.xsl) XSL-FO (PDF) (music2fo.xsl). Many things shown: sorting, grouping, indexing, etc. Query the data: <xsl:apply-templates select="collection/record[@year='1971']/artist"/> returns Genesis Aphrodite's Child Emerson, Lake and Palmer Pink Floyd Example: ChessGML XSLT transforms custom XML to text, XHTML or SVG. ChessGML describes chess games Is produced by chess software, and is not easily readable Not unserstood by browsers XSLT transforms make it possible to display in various formats <?xml version="1.0" encoding="iso-8859-1"?> <game type="chess" variant="classic"> <gameinfo> <eventinfo> <event>The Immortal Game</event> <site>London</site> </eventinfo> <date year="1851"/> <opponents> <white> <player> <person> <surname>Anderssen</surname> <firstname>Adolf</firstname> </person> </player> </white> <black> <player> <person> <surname>Kieseritzky</surname> <firstname>Lionel</firstname> </person> </player> </black> </opponents> <result res="1-0" why="mate"/> </gameinfo> <moves ply-count="23"> <mp> <m c="w"><p c="w" n="p"/><e2/><e4/></m> <m c="b"><p c="b" n="p"/><e7/><e5/></m> </mp> <mp> <m c="w"><p c="w" n="p"/><f2/><f4/></m> <m c="b" capt="1"><p c="b" n="p"/><e5/><f4/></m> </mp> <mp> <m c="w"><p c="w" n="b"/><f1/><c4/></m> <m c="b" chk="1"><p c="b" n="q"/><d8/><h4/></m> </mp> ... <mp> <m c="w"><p c="w" n="b"/><d6/><e7/></m> </mp> </moves> </game> ChessGML to text The Immortal Game London - 1851 White: Anderssen, Adolf Black: Kieseritzky, Lionel 1. e4 e5 2. f4 exf4 3. Bc4 Qh4+ 4. Kf1 b5 5. Bxb5 Nf6 6. Nf3 Qh6 7. d3 Nh5 8. Nh4 Qg5 9. Nf5 c6 10. g4 Nf6 11. Rg1 cxb5 12. h4 Qg6 13. h5 Qg5 14. Qf3 Ng8 15. Bxf4 Qf6 16. Nc3 Bc5 17. Nd5 Qxb2 18. Bd6 Bxg1 19. e5 Qxa1+ 20. Ke2 Na6 21. Nxg7+ Kd8 22. Qf6+ Nxf6 23. Be7 1-0 ChessGML to readable text (or audio devices) The Immortal Game, played in London in 1851, between Adolf Anderssen (white) and Lionel Kieseritzyky, Lionel. One, white pawn to e 4, black pawn to e 5. Two, white pawn to f 4, black pawn takes wite pawn at f 4. Three, white bishop to c 4, black queen to h 4, check. Four, white king to f 1, black pawn to b 5 ... Twenty-three, white bishop to e 7, black resigns. ChessGML to HTML The Immortal Game The Immortal Game Anderssen, Adolf vs. Kieseritzky, Lionel London, 1851 1. e4 1. ... e5 2. f4 ChessGML to SVG (full screen SVG, project page) Example: Slide Generator Variant: these slides have been generated from a single HTML source file (using Amaya to edit text and mathematics) and made into smaller html files: one for each slide XSLT transforms XHTML to XHTML Single XHTML source XSLT stylesheet makes XHTML slides, splitting at each <h2> common style (using CSS) Automatic TOC, forward/back buttons, notes, etc. Easily customisable: display notes or not... Easily extensible: just add more templates to handle more XHTML tags Similar stylesheets could produce text, SVG or XSL-FO from same source. Get Real This is all very nice, but talk to us about production uses. Chess is a niche market, what about myBigCorp's thousands of pages of documentation? Production uses of XSLT within W3C: Many W3C specs: XMLSpec DTD with stylesheets to generate various formats, e.g. MathML 2.0: HTML, XHTML, PDF (2) Math, XSL, SVG: public pages RDF: RDF/XML parser, RDF picture description using SVG Issues management: XML Protocols, WS Architecture, XSLT, XPath Publications: on-line pubrules validator RSS Feeds: W3C home page, MathML, XSL, SVG, Internal WDs DOM: test suite framework WAI: stylesheets used to add ToC to specs TAG: meeting minutes formatting QA: generating the Matrix Get real 2: docbook docbook is probably the most widely used XML Document Management system One source DTD. Example instance: <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V3.1//EN"> <book> <bookinfo> <title>My First Book JaneDoe 1998Jane Doe Foreword ... ... ... ... ... ... ... Many XSLT stylesheets for: Formatting for print publication (heavily used by O'reily publishers): PS, PDF output Formatting for Web sites: HTML, XHTML Formatting for computer documentation (GNOME, FreeBSD, PHP, etc.) Formatting slides Documenting code Formal specifications Theses/dissertations and so on... XSLT in your browser XSLT is supported in browsers Browsers receives XML + XSLT and produces HTML Transformation is done on the spot Browser-side: XSL Page at W3C http://www.w3.org/Style/XSL: XSL page at W3C (source) Source is XML, can be viewed directly HTML version produced off-line (for old browsers) RSS version for news service Browser-side: The Pan-Galactic MathML stylesheet This "hack" shows another use of XSLT in a browser XML: MathML 1 1 + e - 2 π 1 + e - 4 π 1 + e - 6 π 1 + ... = ( 5 + 5 2 - 5 + 1 2 ) e 2 π 5 1 1 + e - ... The problem with MathML: native support vs. plug-in two syntaxes: Inline (Amaya, Mozilla, Netscape 7):...

Here's how to include MathML the right way

x+2 ... Embed (IE plug-ins):...

Here's how to include MathML for plug-ins

... Both syntaxes are incompatible However... The Pan-Galactic MathML stylesheet: solution XSLT can transform one syntax into the other Use the inline syntax Add a stylesheet processing instruction at the beginning of the file: This invokes an XSLT stylesheet that will transform the markup into something the browser understands One standard syntax will work in all the browsers that support MathML Mozilla, Amaya, Netscape 7, IE 5.5/6.0 with plug-ins (or not) XSLT and other XML-related technologies XSLT complies with other XML standards, Therefore it is interoperable with many other technologies A transform can be performed on a DOM XSLT can be part of a chain of processes: Java, Javascript, ASP, PHPetc. Examples: Project management systems, application servers (Cocoon, 4Suite Server, Austin PM, E-speak, Krysalis, etc.) A little bit of history The Past: XSL In the beginning was XSL XSL became XSLT 1.0 and XSL(FO) 1.0 XSLT 1.0 produced XPath 1.0 The present: XSLT quite successful: 25 books, according to Amazon 9 implementation, according to me 122 messages a day on xsl-list (avg. on last 30 days) The Future: XSLT 2.0 New requirements: More functionality Simplify the language Support for new W3C specs: XML Schema, XQuery Remember... XSLT can simplify XML processing It is open technology Specifications available on the Web (w3.org/TR) Royalty-Free material Many Open Source implementations All the tools and specifications used to produce this presentation (Amaya, Mathplayer plug-in, Emacs, Saxon, Adobe SVG, DocBook, etc.) are freely available. Links This presentation: http://www.w3.org/2002/Talks/05-Interop-MaxF/ The XSL page at W3C: http://www.w3.org/Style/XSL This Presenter: mf@w3.org