3 # ----------------------------------------------------------------------------
4 # Generate a dom-filter indexing stylesheet based upon an .abs file
5 # Should be called either this way
7 # abs2dom something.abs > something.xsl
9 # or in a streaming way
11 # something | abs2dom > something.xsl
13 # The output xslt stylesheet generally needs a little bit of tweaking to be
14 # ready for indexing. In particular, watch out for the precedence rules of
15 # xslt templates which work differently from xelm declarations in an .abs file!
21 my $marc_prefix = 'marc';
22 my $supported_rules = {
24 # Supported indexing types:
25 'melm' => \&melm_handler,
26 'xelm' => sub { return $_[1] },
28 # Declarations to ignore:
40 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
41 xmlns:z="http://indexdata.com/zebra-2.0"
42 xmlns:$marc_prefix="http://www.loc.gov/MARC21/slim"
45 <xsl:output indent="yes"
50 <xsl:template match="/">
52 <xsl:apply-templates/>
68 my ($rule) = (/^(\S+)/);
70 if ( defined $supported_rules->{$rule} ) {
71 $handler = $supported_rules->{$rule};
73 if ( $handler == 0 ) {
77 print STDERR "$0: Unsupported indexing rule: '", $rule, "\n\n";
83 my ($index) = (/(\S+)$/);
88 my $xpath = $handler->($rule, $match);
89 my @indexes = split /,/, $index;
91 # To avoid screwing up the <xsl:template match="...."> instruction...
94 print " <xsl:template match=\"$xpath\">\n";
95 print " <z:index name=\"", join(" ", @indexes), "\">\n";
96 print " <xsl:value-of select=\".\"/>\n";
97 print " </z:index>\n";
98 print " </xsl:template>\n\n";
101 print "</xsl:stylesheet>\n";
105 my ($rule, $match) = @_;
106 my ($field, $subfield) = ($match =~ /([^\$]+)\$?(.*)/);
109 if ( $field =~ /^00/ ) {
110 $xpath .= $marc_prefix . ':controlfield[@tag=\'' . $field . '\']';
112 $xpath .= $marc_prefix . ':datafield[@tag=\'' . $field . '\']/' .
113 $marc_prefix . ':subfield';
115 if ( $subfield ne '' ) {
116 $xpath .= '[@code=\'' . $subfield . '\']';