Implemented update action : adelete.
[idzebra-moved-to-github.git] / util / abs2dom
1 #!/usr/bin/perl -w
2
3 # $Id: abs2dom,v 1.3 2007-12-17 12:38:57 sondberg Exp $
4 # ----------------------------------------------------------------------------
5 # Generate a dom-filter indexing stylesheet based upon an .abs file
6 # Should be called either this way
7 #
8 #   abs2dom something.abs > something.xsl
9 #
10 # or in a streaming way
11 #
12 #   something | abs2dom > something.xsl
13 #
14 # The output xslt stylesheet generally needs a little bit of tweaking to be
15 # ready for indexing. In particular, watch out for the precedence rules of
16 # xslt templates which work differently from xelm declarations in an .abs file!
17 #
18 # Good luck!
19
20 use strict;
21
22 print <<END_OF_XSLT;
23 <?xml version="1.0"?>
24 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
25                 xmlns:z="http://indexdata.com/zebra-2.0"
26                 version="1.0">
27
28   <xsl:output indent="yes"
29         method="xml"
30         version="1.0"
31         encoding="UTF-8"/>
32
33   <xsl:template match="/">
34     <z:record>
35       <xsl:apply-templates/>
36     </z:record>
37   </xsl:template>
38
39 END_OF_XSLT
40
41
42 while (<>) {
43     chomp;
44     s/^\s+//;
45     s/\s+$//;
46     next unless s/^xelm\s+//;
47     my ($index) = (/(\S+)$/);
48     s/\s+\Q$index\E$//;
49     my $xpath = $_;
50     my @indexes = split /,/, $index;
51
52     print "  <xsl:template match=\"$xpath\">\n";
53     print "    <z:index name=\"", join(" ", @indexes), "\">\n";
54     print "      <xsl:value-of select=\".\"/>\n";
55     print "    </z:index>\n";
56     print "  </xsl:template>\n\n";
57 }
58
59
60 print "</xsl:stylesheet>\n";