add reader macros
[jackhill/mal.git] / xslt / step1_read_print.xslt
CommitLineData
bfae91cc
A
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- Step 1: Read-Print -->
3<!-- input document must be in the following format -->
4<!--
5<mal>
6 <stdin>...stdin text...</stdin>
7 <stdout> ... ignored, omitted ... </stdout>
8 <state> ignored, preserved </state>
9</mal>
10-->
11<xsl:stylesheet
12 version="3.0"
13 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
14 <xsl:import href="reader.xslt" />
15 <xsl:import href="printer.xslt" />
16 <xsl:output method='xml' encoding='utf-8' indent='yes'/>
17 <xsl:template match="mal" name="rep">
18 <mal>
19 <stdin></stdin> <!-- clear stdin -->
20 <xsl:copy-of select="state" /> <!-- preserve state -->
21 <stdout><xsl:call-template name="PRINT" /></stdout> <!-- copy stdin to stdout -->
22 </mal>
23 </xsl:template>
24
25 <xsl:template name="PRINT">
26 <xsl:variable name="context">
27 <xsl:variable name="ctx">
28 <xsl:call-template name="EVAL" />
29 </xsl:variable>
30 <xsl:for-each select="$ctx">
31 <xsl:variable name="str">
78ec3e62 32 <xsl:call-template name="malprinter-pr_str"><xsl:with-param name="readably" select="true()"/></xsl:call-template>
bfae91cc
A
33 </xsl:variable>
34 <xsl:value-of select="$str" />
35 </xsl:for-each>
36 </xsl:variable>
37 <xsl:for-each select="$context"><xsl:copy-of select="." /></xsl:for-each>
38 </xsl:template>
39
40 <xsl:template name="EVAL">
41 <xsl:variable name="context">
42 <xsl:call-template name="READ" />
43 </xsl:variable>
44 <xsl:for-each select="$context"><xsl:copy-of select="." /></xsl:for-each>
45 </xsl:template>
46
47 <xsl:template name="READ">
48 <xsl:variable name="context">
49 <str>
50 <xsl:copy-of select="stdin/text()" />
51 </str>
52 </xsl:variable>
53 <xsl:variable name="form">
54 <xsl:for-each select="$context">
55 <xsl:call-template name="malreader-read_str"></xsl:call-template>
56 </xsl:for-each>
57 </xsl:variable>
58 <xsl:for-each select="$form">
59 <xsl:if test="error">
60 <xsl:message terminate="yes">
61 <xsl:value-of select="error" />
62 </xsl:message>
63 </xsl:if>
64 <xsl:copy-of select="." />
65 </xsl:for-each>
66 </xsl:template>
67</xsl:stylesheet>