]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xsl/MARC21slimUtils.xsl
moving to new xmlbuilder code for XML / DTD / locale stuff
[Evergreen.git] / Open-ILS / xsl / MARC21slimUtils.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3 <!-- 8/19/04: ntra added "marc:" prefix to datafield element -->
4         <xsl:template name="datafield">
5                 <xsl:param name="tag"/>
6                 <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
7                 <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
8                 <xsl:param name="subfields"/>
9                 <xsl:element name="marc:datafield">
10                         <xsl:attribute name="tag">
11                                 <xsl:value-of select="$tag"/>
12                         </xsl:attribute>
13                         <xsl:attribute name="ind1">
14                                 <xsl:value-of select="$ind1"/>
15                         </xsl:attribute>
16                         <xsl:attribute name="ind2">
17                                 <xsl:value-of select="$ind2"/>
18                         </xsl:attribute>
19                         <xsl:copy-of select="$subfields"/>
20                 </xsl:element>
21         </xsl:template>
22
23         <xsl:template name="subfieldSelect">
24                 <xsl:param name="codes"/>
25                 <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
26                 <xsl:variable name="str">
27                         <xsl:for-each select="marc:subfield">
28                                 <xsl:if test="contains($codes, @code)">
29                                         <xsl:value-of select="text()"/><xsl:value-of select="$delimeter"/>
30                                 </xsl:if>
31                         </xsl:for-each>
32                 </xsl:variable>
33                 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
34         </xsl:template>
35
36         <xsl:template name="buildSpaces">
37                 <xsl:param name="spaces"/>
38                 <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
39                 <xsl:if test="$spaces>0">
40                         <xsl:value-of select="$char"/>
41                         <xsl:call-template name="buildSpaces">
42                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
43                                 <xsl:with-param name="char" select="$char"/>
44                         </xsl:call-template>
45                 </xsl:if>
46         </xsl:template>
47
48         <xsl:template name="chopPunctuation">
49                 <xsl:param name="chopString"/>
50                 <xsl:param name="punctuation"><xsl:text>.:,;/ </xsl:text></xsl:param>
51                 <xsl:variable name="length" select="string-length($chopString)"/>
52                 <xsl:choose>
53                         <xsl:when test="$length=0"/>
54                         <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
55                                 <xsl:call-template name="chopPunctuation">
56                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
57                                         <xsl:with-param name="punctuation" select="$punctuation"/>
58                                 </xsl:call-template>
59                         </xsl:when>
60                         <xsl:when test="not($chopString)"/>
61                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
62                 </xsl:choose>
63         </xsl:template>
64
65         <xsl:template name="chopPunctuationFront">
66                 <xsl:param name="chopString"/>
67                 <xsl:variable name="length" select="string-length($chopString)"/>
68                 <xsl:choose>
69                         <xsl:when test="$length=0"/>
70                         <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
71                                 <xsl:call-template name="chopPunctuationFront">
72                                         <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"/>
73                                 </xsl:call-template>
74                         </xsl:when>
75                         <xsl:when test="not($chopString)"/>
76                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
77                 </xsl:choose>
78         </xsl:template>
79 </xsl:stylesheet>