XSLT file to patch update to the export database

45 views
Skip to first unread message

François Fery

unread,
Jul 20, 2017, 5:34:31 AM7/20/17
to ADBusers
Hello,

I want to patch the export database xml with the three update xml files using xslt. I am learning xslt but I can't find any good example for updating an xml file with another xml file. Does someone already coded a xslt file to update the exported database or know some good example of this ? It would save lot of time thank you in advance.

Best regards.

Alois Treindl

unread,
Jul 20, 2017, 6:19:23 AM7/20/17
to adbu...@googlegroups.com

By update you mean: replace existing entries from the main file with those from a later update?

I am not sure this can be done with xslt.

If I had to do it, I would do it in Perl.

The files consist basically out of junks of <adb_entry>.

read each junk from <adb_entry line to </adb_entry> line.


throw each entry into a hash with adb_id as hash key. The content of each junk needs not to be parsed, it is just a text blob, as far as this small perl program is concerned.

Read all files sequentially, so that updates either replace a hash entry or make a new one.

Then write out the hash, in numerical order of the hash keys.

--
-- You received this message from the Google ADBusers group. To post to this group, send email to adbu...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/adbusers
---
You received this message because you are subscribed to the Google Groups "ADBusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adbusers+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alois Treindl

unread,
Jul 20, 2017, 6:48:52 AM7/20/17
to adbu...@googlegroups.com

I think this does the job:

#! /usr/bin/perl -CIOE
use strict;

my %h = ();
my $head = '';
my $has_data = 0;

while (<>) {
  /<adb_entry adb_id="(\d+)">/ and do {
    my $entry = $_;
    my $id = $1;
    while (<>) {
      $entry .= $_;
      /<\/adb_entry>/ and last;
    }
    $h{$id} = $entry;
    $has_data = 1;
    next;
  };
  if (! $has_data) {
    $head .= $_;
    next;
  }
  /\s*<timestamp/ and do {
    $head .= $_;
    next;
  };
}

my $count = scalar keys %h;
print $head;
foreach (sort { $a <=> $b } keys %h) {
  print $h{$_};
}
print qq|  <adb_entry_count count="$count" />
</astrodatabank_export>
|;

François Fery

unread,
Jul 20, 2017, 11:11:45 AM7/20/17
to ADBusers
Thank you a lot, I will study this.
Best regards.
Reply all
Reply to author
Forward
0 new messages