1 <?xml version="1.0" encoding="utf-8"?>
3 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
5 <xsl:include href="json2xml.xslt"/>
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'"/>
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.) -->
15 <xsl:template match="/">
16 <xsl:for-each select="$tests">
17 <xsl:variable name="file" select="current()"/>
18 <xsl:variable name="json">
20 <xsl:value-of select="unparsed-text(concat($file, '.', $json-ext))"/>
23 <xsl:variable name="xml">
24 <xsl:apply-templates select="$json/json"/>
26 <xsl:result-document href="{$file}.{$xml-ext}" method="xml" indent="yes">
28 <xsl:for-each select="$xml/json/object/field">
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()"/>
34 <xsl:for-each select="object/field[@name eq 'variables']/object/field">
35 <variable name="{@name}">
36 <xsl:copy-of select="*"/>
41 <xsl:for-each select="object/field[@name eq 'testcases']/array/array">
42 <testcase template="{*[1]}" result="{*[2]}"/>
43 </xsl:for-each> </testcases>
47 </xsl:result-document>