corrected typo
[idzebra-moved-to-github.git] / doc / recordmodel-domxml.xml
1 <chapter id="record-model-domxml">
2   <!-- $Id: recordmodel-domxml.xml,v 1.12 2007-03-08 11:29:16 marc Exp $ -->
3   <title>&dom; &xml; Record Model and Filter Module</title>
4   
5   <para>
6    The record model described in this chapter applies to the fundamental,
7    structured &xml;
8    record type <literal>&dom;</literal>, introduced in
9    <xref linkend="componentmodulesdom"/>. The &dom; &xml; record model
10    is experimental, and it's inner workings might change in future
11    releases of the &zebra; Information Server.
12   </para>
13
14   
15   
16   <section id="record-model-domxml-filter">
17    <title>&dom; Record Filter Architecture</title>
18
19      <para>
20       The &dom; &xml; filter uses a standard &dom; &xml; structure as
21       internal data model, and can therefore parse, index, and display 
22       any &xml; document type. It is well suited to work on 
23       standardized &xml;-based formats such as Dublin Core, MODS, METS,
24       MARCXML, OAI-PMH, RSS, and performs equally  well on any other
25       non-standard &xml; format. 
26     </para>
27     <para>
28       A parser for binary &marc; records based on the ISO2709 library
29       standard is provided, it transforms these to the internal
30       &marcxml; &dom; representation. Other binary document parsers
31       are planned to follow.  
32     </para>
33
34     <para>
35       The &dom; filter architecture consists of four
36       different pipelines, each being a chain of arbitrarily many successive
37       &xslt; transformations of the internal &dom; &xml;
38       representations of documents.
39     </para>
40
41     <figure id="record-model-domxml-architecture-fig">
42       <title>&dom; &xml; filter architecture</title>
43       <mediaobject>
44        <imageobject>
45          <imagedata fileref="domfilter.pdf" format="PDF" scale="50"/>
46         </imageobject>
47         <imageobject>
48           <imagedata fileref="domfilter.png" format="PNG"/>
49         </imageobject>
50         <textobject>
51         <!-- Fall back if none of the images can be used -->
52         <phrase>
53           [Here there should be a diagram showing the &dom; &xml;
54            filter architecture, but is seems that your
55            tool chain has not been able to include the diagram in this
56            document.]
57          </phrase>
58         </textobject>
59       </mediaobject>
60      </figure>
61
62
63     <table id="record-model-domxml-architecture-table" frame="top">
64       <title>&dom; &xml; filter pipelines overview</title>
65       <tgroup cols="5">
66        <thead>
67         <row>
68          <entry>Name</entry>
69          <entry>When</entry>
70          <entry>Description</entry>
71          <entry>Input</entry>
72          <entry>Output</entry>
73         </row>
74        </thead>
75        
76        <tbody>
77         <row>
78          <entry><literal>input</literal></entry>
79          <entry>first</entry>
80          <entry>input parsing and initial
81           transformations to common &xml; format</entry>
82          <entry>Input raw &xml; record buffers, &xml;  streams and 
83                 binary &marc; buffers</entry>
84          <entry>Common &xml; &dom;</entry>
85         </row>
86         <row>
87          <entry><literal>extract</literal></entry>
88          <entry>second</entry>
89          <entry>indexing term extraction
90           transformations</entry>
91          <entry>Common &xml; &dom;</entry>
92          <entry>Indexing &xml; &dom;</entry>
93         </row>
94         <row>
95          <entry><literal>store</literal></entry>
96          <entry>second</entry>
97          <entry> transformations before internal document
98           storage</entry>
99          <entry>Common &xml; &dom;</entry>
100          <entry>Storage &xml; &dom;</entry>
101         </row>
102         <row>
103          <entry><literal>retrieve</literal></entry>
104          <entry>third</entry>
105          <entry>multiple document retrieve transformations from
106           storage to different output
107           formats are possible</entry>
108          <entry>Storage &xml; &dom;</entry>
109          <entry>Output &xml; syntax in requested formats</entry>
110         </row>
111        </tbody>
112       </tgroup>
113      </table>
114
115     <para>
116       The &dom; &xml; filter pipelines use &xslt; (and if  supported on
117       your platform, even &exslt;), it brings thus full &xpath;
118       support to the indexing, storage and display rules of not only
119       &xml; documents, but also binary &marc; records.
120     </para>
121    </section>
122
123
124    <section id="record-model-domxml-pipeline">
125     <title>&dom; &xml; filter pipeline configuration</title>   
126
127    <para>
128     The experimental, loadable  &dom; &xml;/&xslt; filter module
129    <literal>mod-dom.so</literal> 
130     is invoked by the <filename>zebra.cfg</filename> configuration statement
131     <screen>
132      recordtype.xml: dom.db/filter_dom_conf.xml
133     </screen>
134     In this example the &dom; &xml; filter is configured to work 
135     on all data files with suffix 
136     <filename>*.xml</filename>, where the configuration file is found in the
137     path <filename>db/filter_dom_conf.xml</filename>.
138    </para>
139
140    <para>The &dom; &xslt; filter configuration file must be
141     valid &xml;. It might look like this:
142     <screen> 
143     <![CDATA[
144     <?xml version="1.0" encoding="UTF8"?>
145     <dom xmlns="http://indexdata.com/zebra-2.0">
146       <input>
147         <xmlreader level="1"/>
148         <!-- <marc inputcharset="marc-8"/> -->
149       </input>
150       <extrac>
151          <xslt stylesheet="common2index.xsl"/>
152       </extract>
153       <store>
154          <xslt stylesheet="common2store.xsl"/>
155       </store>
156       <retrieve name="dc">
157         <xslt stylesheet="store2dc.xsl"/>
158       </retrieve>
159       <retrieve name="mods">
160         <xslt stylesheet="store2mods.xsl"/>
161       </retrieve>
162     </dom>
163     ]]>
164     </screen>
165    </para>
166    <para>
167      The root &xml; element <literal>&lt;dom&gt;</literal> and all other &dom;
168      &xml; filter elements are residing in the namespace 
169      <literal>xmlns="http://indexdata.dk/zebra-2.0"</literal>.
170    </para>
171    <para>
172     All pipeline definition elements - i.e. the
173      <literal>&lt;input&gt;</literal>,
174      <literal>&lt;extract&gt;</literal>,
175      <literal>&lt;store&gt;</literal>, and 
176      <literal>&lt;retrieve&gt;</literal> elements - are optional.
177      Missing pipeline definitions are just interpreted
178      do-nothing identity pipelines.
179    </para>
180    <para>
181     All pipeline definition elements may contain zero or more 
182     <literal><![CDATA[<xslt stylesheet="path/file.xsl"/>]]></literal>
183     &xslt; transformation instructions, which are performed
184     sequentially from top to bottom.
185     The paths in the <literal>stylesheet</literal> attributes
186     are relative to zebras working directory, or absolute to the file
187     system root.
188    </para>
189
190
191    <section id="record-model-domxml-pipeline-input">
192     <title>Input pipeline</title>   
193    <para>
194     The <literal>&lt;input&gt;</literal> pipeline definition element
195     may contain either one &xml; Reader definition
196     <literal><![CDATA[<xmlreader level="1"/>]]></literal>, used to split
197     an &xml; collection input stream into individual &xml; &dom;
198     documents at the prescribed element level, 
199     or one &marc; binary
200     parsing instruction
201     <literal><![CDATA[<marc inputcharset="marc-8"/>]]></literal>, which defines
202     a conversion to &marcxml; format &dom; trees. The allowed values
203     of the <literal>inputcharset</literal> attribute depend on your
204     local <productname>iconv</productname> set-up.
205    </para>
206    <para>
207     Both input parsers deliver individual &dom; &xml; documents to the
208     following chain of zero or more  
209     <literal><![CDATA[<xslt stylesheet="path/file.xsl"/>]]></literal>
210     &xslt; transformations. At the end of this pipeline, the documents
211     are in the common format, used to feed both the 
212      <literal>&lt;extract&gt;</literal> and 
213      <literal>&lt;store&gt;</literal> pipelines.
214    </para>
215    </section>
216
217    <section id="record-model-domxml-pipeline-extract">
218     <title>Extract pipeline</title>   
219      <para>
220        The <literal>&lt;extract&gt;</literal> pipeline takes documents
221        from any common &dom; &xml; format to the &zebra; specific
222         indexing &dom; &xml; format.
223        It may consist of zero ore more 
224        <literal><![CDATA[<xslt stylesheet="path/file.xsl"/>]]></literal>
225        &xslt; transformations, and the outcome is handled to the
226        &zebra; core to drive the process of building the inverted
227        indexes. See
228        <xref linkend="record-model-domxml-canonical-index"/> for
229        details.
230      </para>
231    </section>
232
233    <section id="record-model-domxml-pipeline-store">
234     <title>Store pipeline</title>   
235        The <literal>&lt;store&gt;</literal> pipeline takes documents
236        from any common &dom;  &xml; format to the &zebra; specific
237         storage &dom;  &xml; format.
238        It may consist of zero ore more 
239        <literal><![CDATA[<xslt stylesheet="path/file.xsl"/>]]></literal>
240        &xslt; transformations, and the outcome is handled to the
241        &zebra; core for deposition into the internal storage system.
242     </section>
243
244    <section id="record-model-domxml-pipeline-retrieve">
245     <title>Retrieve pipeline</title>   
246     <para>
247       Finally, there may be one or more 
248       <literal>&lt;retrieve&gt;</literal> pipeline definitions, each
249       of them again consisting of zero or more
250       <literal><![CDATA[<xslt stylesheet="path/file.xsl"/>]]></literal>
251        &xslt; transformations. These are used for document
252       presentation after search, and take the internal storage &dom;
253       &xml; to the requested output formats during record present
254       requests.  
255     </para>
256     <para>
257      The  possible multiple 
258      <literal>&lt;retrieve&gt;</literal> pipeline definitions
259      are distinguished by their unique <literal>name</literal>
260      attributes, these are the literal <literal>schema</literal> or 
261      <literal>element set</literal> names used in 
262       <ulink url="http://www.loc.gov/standards/sru/srw/">&srw;</ulink>,
263       <ulink url="&url.sru;">&sru;</ulink> and
264       &z3950; protocol queries.
265    </para>
266    </section>
267
268
269    <section id="record-model-domxml-canonical-index">
270     <title>Canonical Indexing Format</title>
271
272     <para>
273      &dom; &xml; indexing comes in two flavors: pure
274      processing-instruction governed plain &xml; documents, and - very
275      similar to the Alvis filter indexing format - &xml; documents
276      containing &xml; <literal>&lt;record&gt;</literal> and
277      <literal>&lt;index&gt;</literal> instructions from the magic
278      namespace <literal>xmlns:z="http://indexdata.dk/zebra-2.0"</literal>.
279     </para>
280
281    <section id="record-model-domxml-canonical-index-pi">
282     <title>Processing-instruction governed indexing format</title>
283  
284       <para>The output of the processing instruction driven 
285       indexing &xslt; stylesheets must contain
286       processing instructions named 
287        <literal>zebra-2.0</literal>. 
288       The output of the &xslt; indexing transformation is then
289       parsed using &dom; methods, and the contained instructions are
290       performed on the <emphasis>elements and their
291       subtrees directly following the processing instructions</emphasis>.
292       </para>
293       <para>
294      For example, the output of the command
295      <screen>  
296        xsltproc dom-index-pi.xsl marc-one.xml
297      </screen> 
298      might look like this:
299      <screen>
300       <![CDATA[
301       <?xml version="1.0" encoding="UTF-8"?>
302       <?zebra-2.0 record id=11224466 rank=42?>
303       <record>
304         <?zebra-2.0 index control:0?>
305         <control>11224466</control>
306         <?zebra-2.0 index any:w title:w title:p title:s?>
307         <title>How to program a computer</title>
308       </record>
309       ]]>
310      </screen>
311     </para>
312    </section>
313
314    <section id="record-model-domxml-canonical-index-element">
315     <title>Magic element governed indexing format</title>
316    
317     <para>The output of the indexing &xslt; stylesheets must contain
318     certain elements in the magic 
319      <literal>xmlns:z="http://indexdata.dk/zebra-2.0"</literal>
320     namespace. The output of the &xslt; indexing transformation is then
321     parsed using &dom; methods, and the contained instructions are
322     performed on the <emphasis>magic elements and their
323     subtrees</emphasis>.
324     </para>
325     <para>
326     For example, the output of the command
327      <screen>   
328       xsltproc dom-index-element.xsl marc-one.xml 
329      </screen> 
330      might look like this:
331      <screen>
332       <![CDATA[
333       <?xml version="1.0" encoding="UTF-8"?>
334       <z:record xmlns:z="http://indexdata.com/zebra-2.0" 
335                 z:id="11224466" z:rank="42">
336           <z:index name="control:0">11224466</z:index>
337           <z:index name="any:w title:w title:p title:s">
338                     How to program a computer</z:index>
339       </z:record>
340       ]]>
341      </screen>
342     </para>
343    </section>
344
345
346    <section id="record-model-domxml-canonical-index-semantics">
347     <title>Semantics of the indexing formats</title>
348
349     <para>
350      Both indexing formats are defined with equal semantics and
351      behavior in mind: 
352      <itemizedlist>
353        <listitem>
354          <para>&zebra; specific instructions are either
355          processing instructions named
356          <literal>zebra-2.0</literal> or
357          elements contained in the namespace
358          <literal>xmlns:z="http://indexdata.dk/zebra-2.0"</literal>.
359          </para>
360        </listitem>
361        <listitem>
362          <para>There must be exactly one <literal>record</literal>
363            instruction, which sets the scope for the following,
364            possibly nested <literal>index</literal> instructions. 
365          </para>
366        </listitem>
367        <listitem>
368          <para>The unique <literal>record</literal> instruction
369             may have additional attributes <literal>id</literal> and
370             <literal>rank</literal>, where the value of the opaque ID
371             may be any string not containing the whitespace character 
372             <literal>' '</literal>, and the rank value must be a
373             non-negative integer. See 
374             <xref linkend="administration-ranking"/>
375          </para>
376        </listitem>
377        <listitem>
378          <para> Multiple and possible nested <literal>index</literal>
379          instructions must contain at least one 
380          <literal>indexname:indextype</literal>
381          pair, and may contain multiple such pairs separated by the 
382          whitespace character  <literal>' '</literal>. In each index
383          pair, the name and the type of the index is separated by a 
384          colon character <literal>':'</literal>.
385          </para>  
386        </listitem>
387        <listitem>
388          <para>
389          Any index name consisting of ASCII letters, and following the
390          standard &zebra; rules will do, see 
391          <xref linkend="querymodel-pqf-apt-mapping-accesspoint"/>.
392          </para>  
393        </listitem>
394        <listitem>
395          <para> 
396          Index types are restricted to the values defined in
397          the standard configuration
398          file <filename>default.idx</filename>, see
399          <xref linkend="querymodel-bib1"/> and 
400          <xref linkend="fields-and-charsets"/> for details.
401          </para>
402        </listitem>
403        <listitem>
404          <para> 
405          &dom; input documents which are not resulting in both one
406          unique valid 
407          <literal>record</literal> instruction and one or more valid 
408          <literal>index</literal> instructions can not be searched and
409          found. Therefore,
410          invalid document processing is aborted, and any content of
411          the <literal>&lt;extract&gt;</literal> and 
412          <literal>&lt;store&gt;</literal> pipelines is discarted.
413           A warning is issued in the logs. 
414          </para>
415        </listitem>
416       </itemizedlist>
417     </para>
418
419     
420     <para>The examples work as follows: 
421      From the original &xml; file 
422      <literal>marc-one.xml</literal> (or from the &xml; record &dom; of the
423      same form coming from an <literal>&lt;input&gt;</literal>
424      pipeline),
425      the indexing
426      pipeline <literal>&lt;extract&gt;</literal>
427      produces an indexing &xml; record, which is defined by
428      the <literal>record</literal> instruction
429      &zebra; uses the content of 
430      <literal>z:id="11224466"</literal> 
431      or
432      <literal>id=11224466</literal> 
433      as internal
434      record ID, and - in case static ranking is set - the content of 
435      <literal>rank=42</literal>
436      or
437      <literal>z:rank="42"</literal>
438      as static rank.
439     </para>
440     
441
442     <para>In these examples, the following literal indexes are constructed:
443      <screen>
444        any:w
445        control:0
446        title:w
447        title:p
448        title:s
449      </screen>
450      where the indexing type is defined after the 
451      literal <literal>':'</literal> character.  
452      Any value from the standard configuration
453      file <filename>default.idx</filename> will do.
454      Finally, any 
455      <literal>text()</literal> node content recursively contained
456      inside the <literal>&lt;z:index&gt;</literal> element, or any
457      element following a <literal>index</literal> processing instruction,
458      will be filtered through the
459      appropriate char map for character normalization, and will be
460      inserted in the named indexes.
461     </para>
462     <para>
463      Finally, this example configuration can be queried using &pqf;
464      queries, either transported by &z3950;, (here using a yaz-client) 
465      <screen>
466       <![CDATA[
467       Z> open localhost:9999
468       Z> elem dc
469       Z> form xml
470       Z>
471       Z> find @attr 1=control @attr 4=3 11224466
472       Z> scan @attr 1=control @attr 4=3 ""
473       Z>
474       Z> find @attr 1=title program
475       Z> scan @attr 1=title ""
476       Z>
477       Z> find @attr 1=title @attr 4=2 "How to program a computer"
478       Z> scan @attr 1=title @attr 4=2 ""
479       ]]>
480      </screen>
481      or the proprietary
482      extensions <literal>x-pquery</literal> and
483      <literal>x-pScanClause</literal> to
484      &sru;, and &srw;
485      <screen>
486       <![CDATA[
487       http://localhost:9999/?version=1.1&operation=searchRetrieve&x-pquery=@attr 1=title program
488       http://localhost:9999/?version=1.1&operation=scan&x-pScanClause=@attr 1=title ""
489       ]]>
490      </screen>
491      See <xref linkend="zebrasrv-sru"/> for more information on &sru;/&srw;
492      configuration, and <xref linkend="gfs-config"/> or the &yaz;
493      <ulink url="&url.yaz.cql;">&cql; section</ulink>
494      for the details or the &yaz; frontend server.
495     </para>
496     <para>
497      Notice that there are no <filename>*.abs</filename>,
498      <filename>*.est</filename>, <filename>*.map</filename>, or other &grs1;
499      filter configuration files involves in this process, and that the
500      literal index names are used during search and retrieval.
501     </para>
502     <para>
503      In case that we want to support the usual
504      <literal>bib-1</literal> &z3950; numeric access points, it is a
505      good idea to choose string index names defined in the default
506      configuration file <filename>tab/bib1.att</filename>, see   
507      <xref linkend="attset-files"/>
508     </para>
509     
510    </section>
511
512    </section>
513   </section>
514
515
516   <section id="record-model-domxml-conf">
517    <title>&dom; Record Model Configuration</title>
518
519
520   <section id="record-model-domxml-index">
521    <title>&dom; Indexing Configuration</title>
522     <para>
523      As mentioned above, there can be only one indexing pipeline,
524      and configuration of the indexing process is a synonym
525      of writing an &xslt; stylesheet which produces &xml; output containing the
526      magic processing instructions or elements discussed in  
527      <xref linkend="record-model-domxml-canonical-index"/>. 
528      Obviously, there are million of different ways to accomplish this
529      task, and some comments and code snippets are in order to
530      enlighten the wary.
531     </para>
532     <para>
533      Stylesheets can be written in the <emphasis>pull</emphasis> or
534      the <emphasis>push</emphasis> style: <emphasis>pull</emphasis>
535      means that the output &xml; structure is taken as starting point of
536      the internal structure of the &xslt; stylesheet, and portions of
537      the input &xml; are <emphasis>pulled</emphasis> out and inserted
538      into the right spots of the output &xml; structure. 
539      On the other
540      side, <emphasis>push</emphasis> &xslt; stylesheets are recursively
541      calling their template definitions, a process which is commanded
542      by the input &xml; structure, and is triggered to produce 
543      some output &xml;
544      whenever some special conditions in the input stylesheets are
545      met. The <emphasis>pull</emphasis> type is well-suited for input
546      &xml; with strong and well-defined structure and semantics, like the
547      following &oai; indexing example, whereas the
548      <emphasis>push</emphasis> type might be the only possible way to
549      sort out deeply recursive input &xml; formats.
550     </para>
551     <para> 
552      A <emphasis>pull</emphasis> stylesheet example used to index
553      &oai; harvested records could use some of the following template
554      definitions:
555      <screen>
556       <![CDATA[
557       <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
558        xmlns:z="http://indexdata.dk/zebra-2.0"
559        xmlns:oai="http://www.openarchives.org/&oai;/2.0/" 
560        xmlns:oai_dc="http://www.openarchives.org/&oai;/2.0/oai_dc/" 
561        xmlns:dc="http://purl.org/dc/elements/1.1/"
562        version="1.0">
563
564        <!-- Example pull and magic element style Zebra indexing --> 
565        <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
566
567         <!-- disable all default text node output -->
568         <xsl:template match="text()"/>
569
570         <!-- disable all default recursive element node transversal -->
571         <xsl:template match="node()"/>
572
573          <!-- match only on oai xml record root -->
574          <xsl:template match="/">    
575           <z:record z:id="{normalize-space(oai:record/oai:header/oai:identifier)}">
576            <!-- you may use z:rank="{some XSLT; function here}" -->
577
578            <!-- explicetly calling defined templates -->
579            <xsl:apply-templates/>
580           </z:record>
581          </xsl:template>
582
583          <!-- OAI indexing templates -->
584          <xsl:template match="oai:record/oai:header/oai:identifier">
585           <z:index name="oai_identifier:0">
586            <xsl:value-of select="."/>
587           </z:index>    
588          </xsl:template>
589
590          <!-- etc, etc -->
591
592          <!-- DC specific indexing templates -->
593          <xsl:template match="oai:record/oai:metadata/oai_dc:dc/dc:title">
594           <z:index name="dc_any:w dc_title:w dc_title:p dc_title:s ">
595            <xsl:value-of select="."/>
596           </z:index>
597          </xsl:template>
598
599          <!-- etc, etc -->
600  
601       </xsl:stylesheet>
602       ]]>
603      </screen>
604     </para>
605   </section>
606
607
608   <section id="record-model-domxml-index-marc">
609    <title>&dom; Indexing &marcxml;</title>
610     <para>
611       The &dom; filter allows indexing of both binary &marc; records
612       and &marcxml; records, depending on it's configuration.
613       A typical &marcxml; record might look like this:
614       <screen>  
615       <![CDATA[
616       <record xmlns="http://www.loc.gov/MARC21/slim">
617        <rank>42</rank>
618        <leader>00366nam  22001698a 4500</leader>
619        <controlfield tag="001">   11224466   </controlfield>
620        <controlfield tag="003">DLC  </controlfield>
621        <controlfield tag="005">00000000000000.0  </controlfield>
622        <controlfield tag="008">910710c19910701nju           00010 eng    </controlfield>
623        <datafield tag="010" ind1=" " ind2=" ">
624          <subfield code="a">   11224466 </subfield>
625        </datafield>
626        <datafield tag="040" ind1=" " ind2=" ">
627          <subfield code="a">DLC</subfield>
628          <subfield code="c">DLC</subfield>
629        </datafield>
630        <datafield tag="050" ind1="0" ind2="0">
631          <subfield code="a">123-xyz</subfield>
632        </datafield>
633        <datafield tag="100" ind1="1" ind2="0">
634          <subfield code="a">Jack Collins</subfield>
635        </datafield>
636        <datafield tag="245" ind1="1" ind2="0">
637          <subfield code="a">How to program a computer</subfield>
638        </datafield>
639        <datafield tag="260" ind1="1" ind2=" ">
640          <subfield code="a">Penguin</subfield>
641        </datafield>
642        <datafield tag="263" ind1=" " ind2=" ">
643          <subfield code="a">8710</subfield>
644        </datafield>
645        <datafield tag="300" ind1=" " ind2=" ">
646          <subfield code="a">p. cm.</subfield>
647        </datafield>
648       </record>
649       ]]>
650       </screen>
651     </para>
652
653     <para>
654       It is easily possible to make string manipulation in the &dom;
655       filter. For example, if you want to drop some leading articles
656       in the indexing of sort fields, you might want to pick out the 
657       &marcxml; indicator attributes to chop of leading substrings. If
658       the above &xml; example would have an indicator
659       <literal>ind2="8"</literal> in the title field 
660       <literal>245</literal>, i.e.
661       <screen>  
662       <![CDATA[
663        <datafield tag="245" ind1="1" ind2="8">
664          <subfield code="a">How to program a computer</subfield>
665        </datafield>
666       ]]>
667       </screen>
668       one could write a template taking into account this information
669       to chop the first <literal>8</literal> characters from the
670       sorting index <literal>title:s</literal> like this:
671       <screen>  
672       <![CDATA[
673       <xsl:template match="m:datafield[@tag='245']">
674         <xsl:variable name="chop">
675           <xsl:choose>
676             <xsl:when test="not(number(@ind2))">0</xsl:when>
677             <xsl:otherwise><xsl:value-of select="number(@ind2)"/></xsl:otherwise>
678           </xsl:choose>
679         </xsl:variable>  
680
681         <z:index name="title:w title:p any:w">
682            <xsl:value-of select="m:subfield[@code='a']"/>
683         </z:index>
684
685         <z:index name="title:s">
686           <xsl:value-of select="substring(m:subfield[@code='a'], $chop)"/>
687         </z:index>
688
689       </xsl:template> 
690       ]]>
691       </screen>
692       The output of the above &marcxml; and &xslt; excerpt would then be:
693       <screen>  
694       <![CDATA[
695         <z:index name="title:w title:p any:w">How to program a computer</z:index>
696         <z:index name="title:s">program a computer</z:index>
697       ]]>
698       </screen>
699       and the record would be sorted in the title index under 'P', not 'H'.
700     </para>
701   </section>
702
703
704   <section id="record-model-domxml-index-wizzard">
705    <title>&dom; Indexing Wizardry</title>
706     <para>
707      The names and types of the indexes can be defined in the
708      indexing &xslt; stylesheet <emphasis>dynamically according to
709      content in the original &xml; records</emphasis>, which has
710      opportunities for great power and wizardry as well as grande
711      disaster.  
712     </para>
713     <para>
714      The following excerpt of a <emphasis>push</emphasis> stylesheet
715      <emphasis>might</emphasis> 
716      be a good idea according to your strict control of the &xml;
717      input format (due to rigorous checking against well-defined and
718      tight RelaxNG or &xml; Schema's, for example):
719      <screen>
720       <![CDATA[
721       <xsl:template name="element-name-indexes">     
722        <z:index name="{name()}:w">
723         <xsl:value-of select="'1'"/>
724        </z:index>
725       </xsl:template>
726       ]]>
727      </screen>
728      This template creates indexes which have the name of the working 
729      node of any input  &xml; file, and assigns a '1' to the index.
730      The example query 
731      <literal>find @attr 1=xyz 1</literal> 
732      finds all files which contain at least one
733      <literal>xyz</literal> &xml; element. In case you can not control
734      which element names the input files contain, you might ask for
735      disaster and bad karma using this technique.
736     </para>
737     <para>
738      One variation over the theme <emphasis>dynamically created
739      indexes</emphasis> will definitely be unwise:
740      <screen>
741       <![CDATA[  
742       <!-- match on oai xml record root -->
743       <xsl:template match="/">    
744        <z:record>
745       
746         <!-- create dynamic index name from input content --> 
747         <xsl:variable name="dynamic_content">
748          <xsl:value-of select="oai:record/oai:header/oai:identifier"/>
749         </xsl:variable>
750         
751         <!-- create zillions of indexes with unknown names -->
752         <z:index name="{$dynamic_content}:w">
753          <xsl:value-of select="oai:record/oai:metadata/oai_dc:dc"/>
754         </z:index>          
755        </z:record>
756        
757       </xsl:template>
758       ]]>
759      </screen>
760      Don't be tempted to play too smart tricks with the power of
761      &xslt;, the above example will create zillions of
762      indexes with unpredictable names, resulting in severe &zebra;
763      index pollution..
764     </para>
765   </section>
766
767   <section id="record-model-domxml-debug">
768    <title>Debuggig &dom; Filter Configurations</title>
769    <para>
770     It can be very hard to debug a &dom; filter setup due to the many
771     sucessive &marc; syntax translations, &xml; stream splitting and 
772     &xslt; transformations involved. As an aid, you have always the
773     power of the <literal>-s</literal> command line switch to the 
774     <literal>zebraidz</literal> indexing command at your hand: 
775     <screen>
776      zebraidx -s -c zebra.cfg update some_record_stream.xml
777     </screen>
778     This command line simulates indexing and dumps a lot of debug
779     information in the logs, telling exactly which transformations
780     have been applied, how the documents look like after each
781     transformation, and which record ids and terms are send to the indexer.
782    </para>
783   </section>
784
785   <!--
786   <section id="record-model-domxml-elementset">
787    <title>&dom; Exchange Formats</title>
788    <para>
789      An exchange format can be anything which can be the outcome of an
790      &xslt; transformation, as far as the stylesheet is registered in
791      the main &dom; &xslt; filter configuration file, see
792      <xref linkend="record-model-domxml-filter"/>.
793      In principle anything that can be expressed in  &xml;, HTML, and
794      TEXT can be the output of a <literal>schema</literal> or 
795     <literal>element set</literal> directive during search, as long as
796      the information comes from the 
797      <emphasis>original input record &xml; &dom; tree</emphasis>
798      (and not the transformed and <emphasis>indexed</emphasis> &xml;!!).
799     </para>
800     <para>
801      In addition, internal administrative information from the &zebra;
802      indexer can be accessed during record retrieval. The following
803      example is a summary of the possibilities:
804      <screen>
805       <![CDATA[  
806       <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
807        xmlns:z="http://indexdata.dk/zebra/xslt/1"
808        version="1.0">
809
810        <!- - register internal zebra parameters - ->       
811        <xsl:param name="id" select="''"/>
812        <xsl:param name="filename" select="''"/>
813        <xsl:param name="score" select="''"/>
814        <xsl:param name="schema" select="''"/>
815            
816        <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
817
818        <!- - use then for display of internal information - ->
819        <xsl:template match="/">
820          <z:zebra>
821            <id><xsl:value-of select="$id"/></id>
822            <filename><xsl:value-of select="$filename"/></filename>
823            <score><xsl:value-of select="$score"/></score>
824            <schema><xsl:value-of select="$schema"/></schema>
825          </z:zebra>
826        </xsl:template>
827
828       </xsl:stylesheet>
829       ]]>
830      </screen>
831     </para>
832
833   </section>
834   -->
835
836   <!--
837   <section id="record-model-domxml-example">
838    <title>&dom; Filter &oai; Indexing Example</title>
839    <para>
840      The source code tarball contains a working &dom; filter example in
841      the directory <filename>examples/dom-oai/</filename>, which
842      should get you started.  
843     </para>
844     <para>
845      More example data can be harvested from any &oai; compliant server,
846      see details at the  &oai; 
847      <ulink url="http://www.openarchives.org/">
848       http://www.openarchives.org/</ulink> web site, and the community
849       links at 
850      <ulink url="http://www.openarchives.org/community/index.html">
851       http://www.openarchives.org/community/index.html</ulink>.
852      There is a  tutorial
853      found at
854      <ulink url="http://www.oaforum.org/tutorial/">
855       http://www.oaforum.org/tutorial/</ulink>.
856     </para>
857    </section>
858    -->
859
860   </section>
861
862   
863  </chapter>
864
865
866
867  <!-- Keep this comment at the end of the file
868  Local variables:
869  mode: sgml
870  sgml-omittag:t
871  sgml-shorttag:t
872  sgml-minimize-attributes:nil
873  sgml-always-quote-attributes:t
874  sgml-indent-step:1
875  sgml-indent-data:t
876  sgml-parent-document: "zebra.xml"
877  sgml-local-catalogs: nil
878  sgml-namecase-general:t
879  End:
880  -->