Presentation is loading. Please wait.

Presentation is loading. Please wait.

XSLT programming examples Jaana Holvikivi Metropolia.

Similar presentations


Presentation on theme: "XSLT programming examples Jaana Holvikivi Metropolia."— Presentation transcript:

1 XSLT programming examples Jaana Holvikivi Metropolia

2 J. Holvikivi XML source Stylesheet tree XSLT source Transformation Result tree Source tree XML XHTML text Serialize

3 Case: book printer’s system J. Holvikivi XML database XQueryXSLT SVG, MathML & XHTML PDF XSL-FO XML Editor XML documents

4 J. Holvikivi Recursion: xml file Pennies from heaven Mae West Memories Bertrand Russel Investigations Ludwig Wittgenstein

5 J. Holvikivi Recursion: books.xsl ...continues

6 J. Holvikivi Recursion (continues)

7 J. Holvikivi Sorting, second example

8 J. Holvikivi xsl:sort Moomin belongings sorted

9 J. Holvikivi Generic process for copying

10 J. Holvikivi Variables and parameters: the alphabet one by one ….

11 J. Holvikivi Another HTML example: An XML document representing the results of a soccer tournament 10-Jun-1998 Brazil Scotland 10-Jun-1998 Morocco Norway 16-Jun-1998 Scotland Norway

12 J. Holvikivi Another HTML example, page 2: An XML document representing the results of a soccer tournament 16-Jun-1998 Brazil Morocco 23-Jun-1998 Brazil Norway 23-Jun-1998 Scotland Morocco

13 J. Holvikivi A basic style sheet for the soccer results <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> Results of Group Results of Group versus Played on Result:,

14 J. Holvikivi A style sheet that computes team standings (part 1) <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> Results of Group Team Played Won Drawn Lost For Against

15 J. Holvikivi A style sheet that computes team standings (part 2) <xsl:variable name="won" select="count($matches[team[.=$this]/@score > team[.!=$this]/@score])"/> <xsl:variable name="lost" select="count($matches[team[.=$this]/@score < team[.!=$this]/@score])"/> <xsl:variable name="drawn" select="count($matches[team[.=$this]/@score = team[.!=$this]/@score])"/> <xsl:variable name="for" select="sum($matches/team[.=current()]/@score)"/> <xsl:variable name="against" select="sum($matches[team=current()]/team/@score) - $for"/>

16 J. Holvikivi A style sheet that computes team standings: result  The data are rearranged and processed:

17 J. Holvikivi Explanations create a global variable teams (node-set which has all team elements, the same element cannot be selected twice) this node set is processed in the loop on the next page the dollar sign refers to variable teams declare a local variable this, that gets the value of the current node count($matches[team=$this]) counts the number of those matches for which it is true that the name of this team is in the element value /@score > team[.!=$this]/@score compare values of score attributes: has this team more (> >) scores than the other; != means NOT

18 J. Holvikivi XSL as a functional programming language: the factorial factorial( )

19 J. Holvikivi  1 0"> XSL as a functional programming language: the factorial, cont.


Download ppt "XSLT programming examples Jaana Holvikivi Metropolia."

Similar presentations


Ads by Google