1<?xml version="1.0" encoding="utf-8"?>
2
3<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4
5	<xsl:include href="json2xml.xslt"/>
6
7	<!-- the input test files need to be supplied as a sequence of file names only (no extension) -->
8	<xsl:param name="tests" select="('extended-tests', 'negative-tests', 'spec-examples-by-section', 'spec-examples')"/>
9	<xsl:param name="json-ext" select="'json'"/>
10	<xsl:param name="xml-ext" select="'xml'"/>
11
12	<!-- run this stylesheet with any input to generate the XML test files at output. -->
13	<!-- (a popular way of doing this is to supply the XSLT to itself as the input file.) -->
14
15	<xsl:template match="/">
16		<xsl:for-each select="$tests">
17			<xsl:variable name="file" select="current()"/>
18			<xsl:variable name="json">
19				<json>
20					<xsl:value-of select="unparsed-text(concat($file, '.', $json-ext))"/>
21				</json>
22			</xsl:variable>
23			<xsl:variable name="xml">
24				<xsl:apply-templates select="$json/json"/>
25			</xsl:variable>
26			<xsl:result-document href="{$file}.{$xml-ext}" method="xml" indent="yes">
27				<tests>
28					<xsl:for-each select="$xml/json/object/field">
29						<test name="{@name}">
30							<xsl:if test="exists(object/field[1][@name eq 'level'])">
31								<xsl:attribute name="level" select="object/field[1][@name eq 'level']/integer/text()"/>
32							</xsl:if>
33							<variables>
34								<xsl:for-each select="object/field[@name eq 'variables']/object/field">
35									<variable name="{@name}">
36										<xsl:copy-of select="*"/>
37									</variable>
38								</xsl:for-each>
39							</variables>
40							<testcases>
41								<xsl:for-each select="object/field[@name eq 'testcases']/array/array">
42									<testcase template="{*[1]}" result="{*[2]}"/>
43								</xsl:for-each>									</testcases>
44						</test>
45					</xsl:for-each>
46				</tests>
47			</xsl:result-document>
48		</xsl:for-each>
49	</xsl:template>
50
51</xsl:stylesheet>