]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xsl/locDoc2xml.xsl
stylesheet that can turn the Library of Conference MARC data into a nice XML format
[Evergreen.git] / Open-ILS / xsl / locDoc2xml.xsl
1 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2     <xsl:output omit-xml-declaration="yes" method="xml" encoding="UTF-8" media-type="text/plain" />
3
4     <xsl:template match="/">
5     <fields>
6         <xsl:for-each select="//a[substring(@href,1,5)='#mrcb']">
7             <xsl:call-template name="field">
8                 <xsl:with-param name="datafieldLabel" select="substring-after(@href,'#')"/>
9             </xsl:call-template>
10         </xsl:for-each>
11     </fields>
12     </xsl:template>
13
14     <xsl:template name="field">
15         <xsl:param name="datafieldLabel"/>
16         <xsl:variable name="locatorAnchor" select="//a[@name=$datafieldLabel]"/>
17
18         <xsl:variable name="tagValue" select="substring-before($locatorAnchor, ' - ')"/>
19         <xsl:if test="$tagValue != ''">
20
21             <xsl:variable name="nameStart" select="substring-after($locatorAnchor, ' - ')"/>
22
23             <xsl:variable name="nameValue" select="substring-before($nameStart, '(')"/>
24
25             <xsl:variable name="repeatable" select="substring-after($nameStart, '(')"/>
26             <xsl:variable name="description" select="$locatorAnchor/parent::node()/following-sibling::node()/descendant-or-self::*"/>
27
28             <field>
29                 <xsl:attribute name="tag">
30                     <xsl:value-of select="$tagValue"/>
31                 </xsl:attribute>
32                 <xsl:attribute name="repeatable">
33                     <xsl:choose>
34                         <xsl:when test="substring($repeatable,1,1)='R'">
35                             <xsl:text>true</xsl:text>
36                         </xsl:when>
37                         <xsl:otherwise>
38                             <xsl:text>false</xsl:text>
39                         </xsl:otherwise>
40                     </xsl:choose>
41                 </xsl:attribute>
42
43                 <name>
44                     <xsl:value-of select="normalize-space($nameValue)"/>
45                 </name>
46
47                 <description>
48                     <xsl:value-of select="normalize-space($description)"/>
49                 </description>
50
51                 <xsl:call-template name="indicators">
52                     <xsl:with-param name="indUL" select="$locatorAnchor/parent::node()/following-sibling::h3[.='Indicators'][1]/following-sibling::ul[1]"/>
53                 </xsl:call-template>
54
55                 <xsl:if test="substring($tagValue,1,2) != '00'">
56                     <xsl:call-template name="subfields">
57                         <xsl:with-param name="sfUL" select="$locatorAnchor/parent::node()/following-sibling::h3[.='Subfield Codes'][1]/following-sibling::ul[1]"/>
58                     </xsl:call-template>
59                 </xsl:if>
60
61             </field>
62
63         </xsl:if>
64     </xsl:template>
65
66     <xsl:template name="indicators">
67         <xsl:param name="indUL"/>
68         <xsl:for-each select="$indUL/li">
69             <xsl:if test="string-length(substring-after(.,' - Undefi')) = 0">
70
71                 <xsl:variable name="indPos">
72                     <xsl:choose>
73                         <xsl:when test="starts-with(.,'First')">
74                             <xsl:text>1</xsl:text>
75                         </xsl:when>
76                         <xsl:otherwise>
77                             <xsl:text>2</xsl:text>
78                         </xsl:otherwise>
79                     </xsl:choose>
80                 </xsl:variable>
81
82                 <xsl:for-each select="./ul/li">
83                     <indicator>
84                         <xsl:attribute name="position">
85                             <xsl:value-of select="$indPos"/>
86                         </xsl:attribute>
87
88                         <xsl:attribute name="value">
89                             <xsl:value-of select="substring-before(.,' - ')"/>
90                         </xsl:attribute>
91
92                         <description>
93                             <xsl:value-of select="normalize-space(substring-after(.,' - '))"/>
94                         </description>
95                     </indicator>
96                 </xsl:for-each>
97             </xsl:if>
98         </xsl:for-each>
99     </xsl:template>
100
101     <xsl:template name="subfields">
102         <xsl:param name="sfUL"/>
103         <xsl:for-each select="$sfUL/li">
104             <xsl:variable name="sfCode" select="substring-before(., ' - ')"/>
105             <xsl:variable name="descStart" select="substring-after(., ' - ')"/>
106             <xsl:variable name="descValue" select="substring-before($descStart, '(')"/>
107             <xsl:variable name="sfRepeatable" select="substring-after(., '(')"/>
108
109             <subfield>
110                 <xsl:attribute name="code">
111                     <xsl:value-of select="substring($sfCode,2,1)"/>
112                 </xsl:attribute>
113
114                 <xsl:attribute name="repeatable">
115                     <xsl:choose>
116                         <xsl:when test="substring($sfRepeatable,1,1)='R'">
117                             <xsl:text>true</xsl:text>
118                         </xsl:when>
119                         <xsl:otherwise>
120                             <xsl:text>false</xsl:text>
121                         </xsl:otherwise>
122                     </xsl:choose>
123                 </xsl:attribute>
124
125                 <description>
126                     <xsl:value-of select="normalize-space($descValue)"/>
127                 </description>
128             </subfield>
129         </xsl:for-each>
130     </xsl:template>
131
132 </xsl:stylesheet>
133