Implemented update action : adelete.
[idzebra-moved-to-github.git] / util / abs2dom
index fb20cdc..2daf657 100755 (executable)
@@ -1,20 +1,41 @@
 #!/usr/bin/perl -w
 
-# $Id: abs2dom,v 1.1 2007-12-17 11:48:14 sondberg Exp $
+# $Id: abs2dom,v 1.3 2007-12-17 12:38:57 sondberg Exp $
 # ----------------------------------------------------------------------------
 # Generate a dom-filter indexing stylesheet based upon an .abs file
+# Should be called either this way
+#
+#   abs2dom something.abs > something.xsl
+#
+# or in a streaming way
+#
+#   something | abs2dom > something.xsl
+#
+# The output xslt stylesheet generally needs a little bit of tweaking to be
+# ready for indexing. In particular, watch out for the precedence rules of
+# xslt templates which work differently from xelm declarations in an .abs file!
+#
+# Good luck!
 
 use strict;
 
-my $xslt_header = <<END_OF_XSLT;
-<?xml version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-                    xmlns:z="http://indexdata.com/zebra-2.0"
-                    version="1.0">
+print <<END_OF_XSLT;
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:z="http://indexdata.com/zebra-2.0"
+                version="1.0">
 
   <xsl:output indent="yes"
         method="xml"
         version="1.0"
         encoding="UTF-8"/>
+
+  <xsl:template match="/">
+    <z:record>
+      <xsl:apply-templates/>
+    </z:record>
+  </xsl:template>
+
 END_OF_XSLT
 
 
@@ -23,9 +44,17 @@ while (<>) {
     s/^\s+//;
     s/\s+$//;
     next unless s/^xelm\s+//;
-    my ($indexes) = (/(\S+)$/);
-    s/\s+\Q$indexes\E$//;
+    my ($index) = (/(\S+)$/);
+    s/\s+\Q$index\E$//;
     my $xpath = $_;
+    my @indexes = split /,/, $index;
 
-    print "XPATH='$xpath', INDEX='$indexes'\n"; 
+    print "  <xsl:template match=\"$xpath\">\n";
+    print "    <z:index name=\"", join(" ", @indexes), "\">\n";
+    print "      <xsl:value-of select=\".\"/>\n";
+    print "    </z:index>\n";
+    print "  </xsl:template>\n\n";
 }
+
+
+print "</xsl:stylesheet>\n";