added example of MARCXML indexing with chopping of sort indexes cccording to 'ind2...
[idzebra-moved-to-github.git] / test / xslt / dom-index-element-chop.xsl
1 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2   xmlns:m="http://www.loc.gov/MARC21/slim"
3   xmlns:z="http://indexdata.com/zebra-2.0"
4   exclude-result-prefixes="m z"
5   version="1.0">
6   <!-- $Id: dom-index-element-chop.xsl,v 1.1 2007-03-08 11:24:50 marc Exp $ -->
7   <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
8   
9
10   <xsl:template match="text()"/>
11
12
13   <xsl:template match="/m:record">
14     <z:record z:id="{normalize-space(m:controlfield[@tag='001'])}"
15         z:rank="{normalize-space(m:rank)}">
16       <xsl:apply-templates/>
17     </z:record>
18   </xsl:template>
19
20   <xsl:template match="m:controlfield[@tag='001']">
21     <z:index name="control">
22       <xsl:value-of select="normalize-space(.)"/>
23     </z:index>
24   </xsl:template>
25   
26   <xsl:template match="m:datafield[@tag='245']">
27     <xsl:variable name="chop">
28       <xsl:choose>
29         <xsl:when test="not(number(@ind2))">0</xsl:when>
30         <xsl:otherwise><xsl:value-of select="number(@ind2)"/></xsl:otherwise>
31       </xsl:choose>
32     </xsl:variable>  
33
34     <z:index name="title:w title:p any:w">
35       <xsl:value-of select="m:subfield[@code='a']"/>
36     </z:index>
37
38     <z:index name="title:s">
39       <xsl:value-of select="substring(m:subfield[@code='a'], $chop)"/>
40     </z:index>
41
42   </xsl:template>
43
44 </xsl:stylesheet>