Commit | Line | Data |
---|---|---|
b10698ec A |
1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:map="http://www.w3.org/2005/xpath-functions/map" xmlns:env="http://www.w3.org/2005/02/xpath-functions"> | |
3 | <!-- since I can not, for the life of me, figure out how to (de-)serialise maps from/to xml, we're gonna be storing the env as a json string --> | |
4 | <xsl:function name="env:set"> | |
5 | <xsl:param name="env"/> | |
6 | <xsl:param name="name"/> | |
7 | <xsl:param name="value"/> | |
8 | <xsl:sequence select="map { 'outer': $env('outer'), 'data': map:put(map:merge($env('data')), $name, $value => serialize()) }"/> | |
9 | </xsl:function> | |
10 | ||
11 | <xsl:function name="env:find"> | |
12 | <xsl:param name="env"/> | |
13 | <xsl:param name="name"/> | |
14 | <xsl:sequence select="if (empty($env)) then () else if (map:contains($env('data'), $name)) then $env else env:find($env('outer'), $name)"/> | |
15 | </xsl:function> | |
16 | ||
17 | <xsl:function name="env:get"> | |
18 | <xsl:param name="env"/> | |
19 | <xsl:param name="name"/> | |
20 | <xsl:variable name="value" select="let $venv := env:find($env, $name) return if (empty($venv)) then () else $venv('data')($name)"></xsl:variable> | |
21 | <xsl:choose> | |
22 | <xsl:when test="empty($value)"><xsl:message terminate="yes">Symbol <xsl:value-of select="$name" /> not found</xsl:message></xsl:when> | |
23 | <xsl:otherwise><xsl:sequence select="parse-xml($value)"/></xsl:otherwise> | |
24 | </xsl:choose> | |
25 | </xsl:function> | |
26 | ||
27 | <xsl:function name="env:base" as="xs:string"> | |
28 | <xsl:variable name="plus"><malval kind="function" name="+"></malval></xsl:variable> | |
29 | <xsl:variable name="minus"><malval kind="function" name="-"></malval></xsl:variable> | |
30 | <xsl:variable name="mult"><malval kind="function" name="*"></malval></xsl:variable> | |
31 | <xsl:variable name="div"><malval kind="function" name="/"></malval></xsl:variable> | |
32 | <xsl:sequence select="env:serialise(env:set(env:set(env:set(env:set(map{'outer':(), 'data':map{}}, '+', $plus), '-', $minus), '*', $mult), '/', $div))"/> | |
33 | </xsl:function> | |
34 | ||
35 | <xsl:function name="env:serialise"> | |
36 | <xsl:param name="env"/> | |
37 | <xsl:sequence select="serialize($env, map {'method': 'json'})"/> | |
38 | </xsl:function> | |
39 | ||
40 | <xsl:function name="env:close"> | |
41 | <xsl:param name="env"/> | |
42 | <xsl:sequence select="map {'outer': $env, 'data': map{}}"/> | |
43 | </xsl:function> | |
44 | ||
45 | <xsl:function name="env:deserialise"> | |
46 | <xsl:param name="env"/> | |
47 | <xsl:sequence select="parse-json($env)"/> | |
48 | </xsl:function> | |
49 | ||
50 | </xsl:stylesheet> |