Skip to content

Commit

Permalink
add 'xpath-eval', and fix most running issues
Browse files Browse the repository at this point in the history
- step7 still has the replEnv-values-are-not-captured issue
  • Loading branch information
alimpfard committed May 23, 2020
1 parent d83ad64 commit 4c50b67
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ step5_EXCLUDES += plpgsql # too slow for 10,000
step5_EXCLUDES += plsql # too slow for 10,000
step5_EXCLUDES += powershell # too slow for 10,000
step5_EXCLUDES += $(if $(filter cpp,$(haxe_MODE)),haxe,) # cpp finishes 10,000, segfaults at 100,000
step5_EXCLUDES += xslt # iteration cannot be expressed

dist_EXCLUDES += mal
# TODO: still need to implement dist
Expand All @@ -157,6 +158,7 @@ mal_TEST_OPTS = --start-timeout 60 --test-timeout 180
else ifeq ($(MAL_IMPL),powershell)
mal_TEST_OPTS = --start-timeout 60 --test-timeout 180
endif
xslt_TEST_OPTS = --test-timeout 120


#
Expand Down
7 changes: 6 additions & 1 deletion impls/xslt/core.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,12 @@
</xsl:choose>
</xsl:when>
<xsl:when test="$func/malval/@name = 'xpath-eval'" >

<xsl:message>
<request kind="xpath-eval" value="{$args/value/malval/lvalue/malval[1]/@value}" context="{$args/value/malval/lvalue/malval[2] => serialize()}"/>
</xsl:message>
<value>
<xsl:sequence select="document('xsl_input-string')"/>
</value>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="error(QName('MAL', 'Error'), concat('Invalid function ', $func), core:makeMALValue(concat('Invalid function ', $func), 'string'))" />
Expand Down
8 changes: 7 additions & 1 deletion impls/xslt/env.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<xsl:choose>
<xsl:when test="empty($value)">
<xsl:variable name="apos" select='"&apos;"'></xsl:variable>
<xsl:value-of select="error(QName('MAL', 'Error'), concat($apos, $name, $apos, ' not found'), core:makeMALValue(concat($apos, $name, $apos, ' not found'), 'string'))" />
<xsl:value-of select="error(QName('MAL', 'Error'), concat($apos, $name, $apos, ' not found'), fn:makeMALValue(concat($apos, $name, $apos, ' not found'), 'string'))" />
</xsl:when>
<xsl:otherwise><xsl:sequence select="parse-xml($value)"/></xsl:otherwise>
</xsl:choose>
Expand Down Expand Up @@ -189,4 +189,10 @@
<xsl:sequence select="parse-json($env)"/>
</xsl:function>

<xsl:function name="fn:makeMALValue">
<xsl:param name="value"/>
<xsl:param name="kind"/>
<malval kind="{$kind}" value="{$value}"/>
</xsl:function>

</xsl:stylesheet>
15 changes: 15 additions & 0 deletions impls/xslt/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ def serve_one_request():
with open('xsl_input-string', 'w') as fx:
fx.write(str(int(x)))
# stdout.write('\n')
elif req.attrib['kind'] == 'xpath-eval':
xpath = req.attrib['value']
with open('xsl-eval.xslt', 'w') as f:
f.write(f'<?xml version="1.0" encoding="UTF-8"?><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="ENV" xmlns:core="CORE" exclude-result-prefixes="env core xs xsl map fn"><xsl:output omit-xml-declaration="yes"/><xsl:template match="/"><xsl:sequence select="{xpath}" /></xsl:template></xsl:stylesheet>')
with open('xsl-null.xml', 'w') as f:
f.write(req.attrib['context'])

if os.system(f'saxon -xsl:xsl-eval.xslt -s:xsl-null.xml > xsl-eval_output.xml'):
x = ''
else:
with open('xsl-eval_output.xml', 'r') as f:
x = f.read()
with open('xsl_input-string', 'w') as fx:
fx.write(x)
# stdout.write('\n')
except Exception as e:
# if str(e) != 'no element found: line 1, column 0':
# f.seek(0)
Expand Down

0 comments on commit 4c50b67

Please sign in to comment.