explicitely callable named templates with parameters:
Download presentation
Presentation is loading. Please wait.
1
Notes 5.2: Computing with XSLT
XSLT is a declarative rule-based language for a special purpose: XML transformation Can we express procedural computations with XSLT? What is the exact computational power of XSLT? We've seen some programming-like features: iteration over selected source nodes (xsl:for-each) conditional evaluation (xsl:if and xsl:choose) SDPL 2003 Notes 5.2: Computing with XSLT
2
Notes 5.2: Computing with XSLT
Further programming-like features: variables (names bound to non-updatable values): <xsl:for-each select="//name"> <xsl:variable name="LAndF" select="concat(last, ', ', first)" /> </xsl:for-each> explicitely callable named templates with parameters: <xsl:call-template name="process-name"> <xsl:with-param name="pname" select="$LAndF" /> </xsl:call-template> SDPL 2003 Notes 5.2: Computing with XSLT
3
Notes 5.2: Computing with XSLT
A Real-Life Example We used LaTex to format an XML article. For this, source table structures <tgroup cols="3"> </tgroup> had to be mapped to corresponding LaTex environments: \begin{tabular}{lll} %3 left-justified cols \end{tabular} How to do this? SDPL 2003 Notes 5.2: Computing with XSLT
4
Notes 5.2: Computing with XSLT
Solution (1/2) Pass the count of columns to a named template which generates an appropriate number of ‘l’s: <xsl:template match="tgroup"> \begin{tabular}{ } <xsl:apply-templates /> \end{tabular} </xsl:template> <xsl:call-template name="gen-cols"> <xsl:with-param name="count" /> <xsl:with-param name="symb" select="'l'" /> </xsl:call-template> SDPL 2003 Notes 5.2: Computing with XSLT
5
Solution 2/2: Recursive gen-cols
<xsl:template name="gen-cols"> <xsl:param name="count" /> <xsl:param name="symb" /> <xsl:if test="$count > 0"> <xsl:value-of select="$symb" /> <xsl:call-template name="gen-cols"> <xsl:with-param name="count" select="$count - 1" /> <xsl:with-param name="symbol" select="$symbol" /> </xsl:call-template> </xsl:if> </xsl:template> SDPL 2003 Notes 5.2: Computing with XSLT
6
Computational power of XSLT
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? We can show that any algorithmic computation can be simulated with XSLT shown indirectly, through simulating Turing machines by XSLT SDPL 2003 Notes 5.2: Computing with XSLT
7
Notes 5.2: Computing with XSLT
Turing machine Alan Turing 1936/37 formal model of algorithms primitive but powerful to simulate any computation expressible in any algorithmic model (Church/Turing thesis) Turing machine A finite set of states unlimited tape of cells for symbols, examined by a tape head SDPL 2003 Notes 5.2: Computing with XSLT
8
Illustration of a Turing Machine
1 1 1 1 state-based control SDPL 2003 Notes 5.2: Computing with XSLT
9
Control of a Turing machine
Control defined by a transition function s: s(q, a) = (q´, b, d), where d {left, right} Meaning: with current state q and tape symbol a, move to new state q´ 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 SDPL 2003 Notes 5.2: Computing with XSLT
10
The “transition” template
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 SDPL 2003 Notes 5.2: Computing with XSLT
11
Overall structure of the simulation
<xsl:template name="transition"> <!-- parameters and trace output omitted --> <xsl:choose> <xsl:when test="$state='YES'"> <ACCEPT /> </xsl:when> <!-- an xsl:when for simulating each defined single transition comes here > <xsl:otherwise> <REJECT /> </xsl:choose> </ xsl:template> SDPL 2003 Notes 5.2: Computing with XSLT
12
Updating the representation of the tape
For each right-move s(q, a) = (q´, b, right), concatenate 'b' at the end of $left and drop the first character of $right Left-moves s(q1, a) = (q2, 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' Example: a TM for palindromes over alphabet {a, b}; ('#' used for denoting blank tape slots) SDPL 2003 Notes 5.2: Computing with XSLT
13
Simulating a single transition (1/2)
<!-- sigma(mark,a) = (move_a,#,right): --> <xsl:when test="$state='mark' and substring($right, 1, 1)='a'"> <!-- First update the parameters: --> <xsl:variable name="newstate" select="'move_a'"/> <xsl:variable name="newleft" select="concat($left, '#')"/> <xsl:variable name="newright" select="substring($right, 2)"/> SDPL 2003 Notes 5.2: Computing with XSLT
14
Simulating a single transition (2/2)
<!-- Then call "transition" with new params: --> <xsl:call-template name="transition"> <xsl:with-param name="state" select="$newstate"/> <xsl:with-param name="left" select= "$newleft"/> <xsl:with-param name = "right" select="$newright"/> </xsl:call-template> </xsl:when> SDPL 2003 Notes 5.2: Computing with XSLT
15
Sample trace of the simulation
$ saxon dummy.xml tm-palindr.xsl input-tape=aba <M state="#[mark]aba#"/> <M state="##[move_a]ba#"/> <M state="##b[move_a]a#"/> <M state="##ba[move_a]#"/> <M state="##b[test_a]a#"/> <M state="##[return]b##"/> <M state="#[return]#b##"/> <M state="##[mark]b##"/> <M state="###[move_b]##"/> <M state="##[test_b]###"/> <M state="#[YES]####"/> <ACCEPT/> state shown as tape-left[state]tape-right SDPL 2003 Notes 5.2: Computing with XSLT
16
Notes 5.2: Computing with XSLT
What does this mean? XSLT has full algorithmic 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 SDPL 2003 Notes 5.2: Computing with XSLT
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.