3 # $Id: abs2dom,v 1.4 2007-12-20 11:44:18 sondberg Exp $
4 # ----------------------------------------------------------------------------
5 # Generate a dom-filter indexing stylesheet based upon an .abs file
6 # Should be called either this way
8 # abs2dom something.abs > something.xsl
10 # or in a streaming way
12 # something | abs2dom > something.xsl
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!
22 my $marc_prefix = 'marc';
23 my $supported_rules = {
25 # Supported indexing types:
26 'melm' => \&melm_handler,
27 'xelm' => sub { return $_[1] },
29 # Declarations to ignore:
41 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
42 xmlns:z="http://indexdata.com/zebra-2.0"
43 xmlns:$marc_prefix="http://www.loc.gov/MARC21/slim"
46 <xsl:output indent="yes"
51 <xsl:template match="/">
53 <xsl:apply-templates/>
69 my ($rule) = (/^(\S+)/);
71 if ( defined $supported_rules->{$rule} ) {
72 $handler = $supported_rules->{$rule};
74 if ( $handler == 0 ) {
78 print STDERR "$0: Unsupported indexing rule: '", $rule, "\n\n";
84 my ($index) = (/(\S+)$/);
89 my $xpath = $handler->($rule, $match);
90 my @indexes = split /,/, $index;
92 # To avoid screwing up the <xsl:template match="...."> instruction...
95 print " <xsl:template match=\"$xpath\">\n";
96 print " <z:index name=\"", join(" ", @indexes), "\">\n";
97 print " <xsl:value-of select=\".\"/>\n";
98 print " </z:index>\n";
99 print " </xsl:template>\n\n";
102 print "</xsl:stylesheet>\n";
106 my ($rule, $match) = @_;
107 my ($field, $subfield) = ($match =~ /([^\$]+)\$?(.*)/);
110 if ( $field =~ /^00/ ) {
111 $xpath .= $marc_prefix . ':controlfield[@tag=\'' . $field . '\']';
113 $xpath .= $marc_prefix . ':datafield[@tag=\'' . $field . '\']/' .
114 $marc_prefix . ':subfield';
116 if ( $subfield ne '' ) {
117 $xpath .= '[@code=\'' . $subfield . '\']';