summaryrefslogtreecommitdiffstats
path: root/test/samples/w3c/convert-tests.pl
blob: 9c91e3c9372cf8f79d8b4e5fdf6f41a65c9c6e11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/opt/local/bin/perl -w

use strict;

use XML::LibXSLT;
use XML::LibXML;
use Data::Dumper;

my $xslt = XML::LibXSLT->new();
my $xsl = shift || 'confEcma.xsl';

opendir(my $testDir, "tests") or die($!);
opendir(my $txmlDir, "txml") or die($!);
while(readdir $txmlDir) {
  next unless /txml$/;
  my $baseName = $_;
  my $txmlFile = 'txml/'.$_;
  
  my $source = XML::LibXML->load_xml(location => $txmlFile) or die($!);
  my $style_doc = XML::LibXML->load_xml(location => $xsl, no_cdata=>1) or die($!);
  
  my $stylesheet = $xslt->parse_stylesheet($style_doc) or die($!);
  my $results = $stylesheet->transform($source) or die($!);
    
  open(my $json, '>', "tests/".$baseName.".json") or die($!);
  print $json <<EOF;
{
    "initialConfiguration" : ["pass"],
    "events" : []
}
EOF
  close($json);

  open(my $scxml, '>', "tests/".$baseName.".scxml") or die($!);
  print $scxml $stylesheet->output_as_bytes($results);
  close($scxml);
}