And again -bill!
----- Forwarded message from [email protected] ----- Date: Wed, 14 Jul 2010 17:38:18 -0700 From: [email protected] Subject: Auto-discard notification To: [email protected] The attached message has been automatically discarded. Date: Wed, 14 Jul 2010 16:43:24 -0700 From: Dylan Beaudette <[email protected]> Subject: Re: [vox-tech] complex XML to CSV via XSLT To: [email protected] Cc: Wes Hardaker <[email protected]> Reply-To: [email protected] Wow. Pretty neat. Looks like that almost works. It does not work when there are several 'pedons' in the collection. Ideas? Dylan On Wednesday 14 July 2010, Wes Hardaker wrote: > >>>>> On Wed, 14 Jul 2010 11:40:35 -0700, Dylan Beaudette > >>>>> <[email protected]> said: > > DB> I would like to generalize some sample XSLT documents to convert the > DB> entire file into a sequence of CSV files. > > Remember, that whatever you do in another language you can do in perl > with less code and more obfuscation: > > use XML::Simple; > use IO::File; > use strict; > > my $doc = XMLin($ARGV[0], SuppressEmpty => '', KeyAttr => 'foobarbogus'); > my %iohandles; > > $doc = $doc->{'pedon'}; > > foreach my $key (keys(%$doc)) { > if (!exists($iohandles{$key})) { > die "I'm being hacked" if ($key !~ /^[_a-zA-Z0-9]/); > $iohandles{$key} = new IO::File; > $iohandles{$key}->open(">$key.csv"); > print STDERR "writing out $key.csv\n"; > } > if (ref($doc->{$key}) ne 'HASH') { > next; > } > foreach my $subkey (keys(%{$doc->{$key}})) { > if (ref($doc->{$key}{$subkey}) ne 'ARRAY') { > if (ref($doc->{$key}{$subkey}) ne 'HASH') { > print STDERR "{$key}{$subkey} unexpected type\n"; > last; > } > $doc->{$key}{$subkey} = [$doc->{$key}{$subkey}]; > } > foreach my $record (@{$doc->{$key}{$subkey}}) { > $iohandles{$key}->print(join(",",values(%$record)),"\n"); > } > } > } > > # perl hack.pl pedons.xml > writing out hz_mottles.csv > writing out hz_frags.csv > writing out horizon.csv > writing out hz_roots.csv > writing out memo.csv > writing out description.csv > {description}{surface_frags_bd} unexpected type > writing out hz_pores.csv > writing out hz_pvsf.csv > writing out notes.csv > writing out hz_rmf.csv > writing out diagnostic.csv > writing out vegetation.csv > writing out pedon_spatial.csv > {pedon_spatial}{y} unexpected type -- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341 ----- End forwarded message ----- -- -bill! Sent from my computer _______________________________________________ vox-tech mailing list [email protected] http://lists.lugod.org/mailman/listinfo/vox-tech
