Presentation is loading. Please wait.

Presentation is loading. Please wait.

SDPL 2002Notes 5.2: Computing with XSLT1 5.2 Computing with XSLT n XSLT is principally a declarative rule-based language –Can we express procedural computations.

Similar presentations


Presentation on theme: "SDPL 2002Notes 5.2: Computing with XSLT1 5.2 Computing with XSLT n XSLT is principally a declarative rule-based language –Can we express procedural computations."— Presentation transcript:

1 SDPL 2002Notes 5.2: Computing with XSLT1 5.2 Computing with XSLT n XSLT is principally a declarative rule-based language –Can we express procedural computations with XSLT? –What is the exact computational power of XSLT? n We've seen some programming-like features: –iteration over selected source nodes ( xsl:for-each ) –conditional evaluation ( xsl:if and xsl:choose )

2 SDPL 2002Notes 5.2: Computing with XSLT2 Computing with XSLT n Further programming-like features: –limited variables (names bound to values): … –explicitely callable named templates with parameters: … –explicitely callable named templates with parameters: …

3 SDPL 2002Notes 5.2: Computing with XSLT3 A Real-Life Example We used LaTex to format an XML article. For this, source table structures... had to be mapped to corresponding LaTex environments: \begin{tabular}{lll} %3 left-justified cols... \end{tabular} We used LaTex to format an XML article. For this, source table structures... had to be mapped to corresponding LaTex environments: \begin{tabular}{lll} %3 left-justified cols... \end{tabular} n How to do this?

4 SDPL 2002Notes 5.2: Computing with XSLT4 Solution (1/2) Pass the column count to a named template which generates an appropriate number of ‘l’s: Pass the column count to a named template which generates an appropriate number of ‘l’s: \begin{tabular}{ \begin{tabular}{ } } \end{tabular} \end{tabular}

5 SDPL 2002Notes 5.2: Computing with XSLT5 Solution 2/2: Recursive gen-cols 0"> 0"> </xsl:template>

6 SDPL 2002Notes 5.2: Computing with XSLT6 Computational power of XSLT n XSLT seems quite powerful, but how powerful is it? –Implementations may provide extension mechanisms, e.g., to call arbitrary Java methods –Are there limits to XSLT processing that we can do without extensions? n We can show that any algorithmic computation can be simulated with XSLT –shown indirectly, through simulating Turing machines by XSLT

7 SDPL 2002Notes 5.2: Computing with XSLT7 Turing machine n Alan Turing 1936/37 n formal model of algorithms n primitive but powerful to simulate any computation expressible in any algorithmic model (Church/Turing thesis) n Turing machine –A finite set of states –unlimited tape of cells for symbols, examined by a tape head

8 SDPL 2002Notes 5.2: Computing with XSLT8 Illustration of a Turing Machine 0 10 0 1 1 1 state-basedcontrol

9 SDPL 2002Notes 5.2: Computing with XSLT9 Control of a Turing machine Control defined by a transition function   (q 1, a) = (q 2, b, d), where d  {left, right} Control defined by a transition function   (q 1, a) = (q 2, b, d), where d  {left, right} –Meaning: with current state q 1 and tape symbol a, »move to new state q 2 »write new symbol 'b' at the place of 'a' »move tape-head one step in direction d Such control can be simulated in XSLT with a recursive named-template; Call it transition Such control can be simulated in XSLT with a recursive named-template; Call it transition

10 SDPL 2002Notes 5.2: Computing with XSLT10 The “ transition ” template n Parameters: –state : the current state –left : contents of the tape up to the tape head –right : contents of the tape starting at the cell pointed by the tape head Transition simulates a single transition step; calls itself with updated parameters Transition simulates a single transition step; calls itself with updated parameters

11 SDPL 2002Notes 5.2: Computing with XSLT11 Overall structure of the simulation <xsl:choose> </xsl:when> </xsl:when></xsl:choose>

12 SDPL 2002Notes 5.2: Computing with XSLT12 Updating the representation of the tape For each right-move  (q 1, a) = (q 2, b, right), concatenate 'b' at the end of $left and drop the first character of $right For each right-move  (q 1, a) = (q 2, b, right), concatenate 'b' at the end of $left and drop the first character of $right Left-moves  (q 1, a) = (q 2, b, left) in a similar manner: Left-moves  (q 1, a) = (q 2, b, left) in a similar manner: –drop the last character of $left, and concatenate it in front of $right whose first character has been replaced by 'b' n Example: a TM for palindromes over alphabet {a, b}; ('#' used for denoting blank tape slots)

13 SDPL 2002Notes 5.2: Computing with XSLT13 Simulating a single transition (1/2)

14 SDPL 2002Notes 5.2: Computing with XSLT14 Simulating a single transition (2/2) </xsl:when>

15 SDPL 2002Notes 5.2: Computing with XSLT15 Sample trace of the simulation $ saxon dummy.xml tm-palindr.xsl input-tape=aba <ACCEPT/> state shown as tape-left[state]tape-right

16 SDPL 2002Notes 5.2: Computing with XSLT16 What does this mean? n XSLT has full algorithmic programming power –(It is "Turing-complete") –Is this intentional? »Inconvenient as a general-purpose programming language! –Impossible to recognise non-terminating transformations automatically (  the "halting problem" has no algorithmic solution) »Malicious hacker could cause "denial-of-service" through non- terminating style sheets


Download ppt "SDPL 2002Notes 5.2: Computing with XSLT1 5.2 Computing with XSLT n XSLT is principally a declarative rule-based language –Can we express procedural computations."

Similar presentations


Ads by Google