We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

User:Taneb/XSLT S and K

From Esolang
Jump to navigation Jump to search

XSLT S and K is an attempt to demonstrate the Turing Completeness of XSLT (a language proposed by the W3C for transforming one XML document to another) by writing an S and K combinatory logic interpreter doohickey.

The combinator has to be in a certain format: this is the format for the identity function SKK:

<s><k/><k/></s>

And for a version of Iota's universal combinator s(s(skk)(ks))(kk):

<s><s><s><k/><k/></s><k><s/></k></s><k><k/></k></s>

This may or may not work. It is suspected that either it does only one pass, or it doesn't work at all.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//s/*[3]/..">
	<xsl:element name="{./*[1]}">
		<xsl:value-of select="."/>
		<xsl:copy-of  select="../*[3]"/>
		<xsl:element name="{../[2]}">
			<xsl:value-of select="."/>
			<xsl:copy-of select="../*[3]"/>
		</xsl:element>
	</xsl:element>
	<xsl:for-each select="./*[position()>3]">
		<xsl:copy-of select="."/>
	</xsl:for-each>
</xsl:template>
<xsl:template match="//k/*[2]/..">
	<xsl:copy-of select="./*[1]"/>
	<xsl:for-each select="./*[position()>2">
		<xsl:copy-of select="."/>	
	</xsl:for-each>
</xsl:template>
<xsl:template match="/*[2]/..">
	<xsl:element name="{./*[1]}">
		<xsl:value-of select="."/>
		<xsl:copy-of select="../*[2]"/>		
	</xsl:element>
</xsl:template>
</xsl:transform>

This does not work in Internet Explorer. If you really want to run it on IE, decrement numbers is square brackets.