Fix documentation of of chr's equivalent directive ZEB-672
[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   <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
7   
8
9   <xsl:template match="text()"/>
10
11
12   <xsl:template match="/m:record">
13     <z:record z:id="{normalize-space(m:controlfield[@tag='001'])}"
14         z:rank="{normalize-space(m:rank)}">
15       <xsl:apply-templates/>
16     </z:record>
17   </xsl:template>
18
19   <xsl:template match="m:controlfield[@tag='001']">
20     <z:index name="control">
21       <xsl:value-of select="normalize-space(.)"/>
22     </z:index>
23   </xsl:template>
24   
25   <xsl:template match="m:datafield[@tag='245']">
26     <xsl:variable name="chop">
27       <xsl:choose>
28         <xsl:when test="not(number(@ind2))">0</xsl:when>
29         <xsl:otherwise><xsl:value-of select="number(@ind2)"/></xsl:otherwise>
30       </xsl:choose>
31     </xsl:variable>  
32
33     <z:index name="title:w title:p any:w">
34       <xsl:value-of select="m:subfield[@code='a']"/>
35     </z:index>
36
37     <z:index name="title:s">
38       <xsl:value-of select="substring(m:subfield[@code='a'], $chop)"/>
39     </z:index>
40
41   </xsl:template>
42
43 </xsl:stylesheet>