|
Line 0
Link Here
|
| 0 |
- |
1 |
<xsl:stylesheet version="1.0" |
|
|
2 |
xmlns="http://www.loc.gov/MARC21/slim" |
| 3 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 4 |
xmlns:msxml="urn:schemas-microsoft-com:xslt" |
| 5 |
> |
| 6 |
<xsl:output encoding="UTF-8" indent="yes" method="xml"/> |
| 7 |
<xsl:strip-space elements="*"/> |
| 8 |
|
| 9 |
<!-- |
| 10 |
Transformation from UNIMARC XML representation to MARCXML. |
| 11 |
Based upon http://www.loc.gov/marc/unimarctomarc21.html |
| 12 |
|
| 13 |
--> |
| 14 |
<xsl:template match="/"> |
| 15 |
<xsl:choose> |
| 16 |
<xsl:when test="//collection"> |
| 17 |
<collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> |
| 18 |
<xsl:for-each select="//collection/record"> |
| 19 |
<record> |
| 20 |
<xsl:call-template name="record"/> |
| 21 |
</record> |
| 22 |
</xsl:for-each> |
| 23 |
</collection> |
| 24 |
</xsl:when> |
| 25 |
<xsl:otherwise> |
| 26 |
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> |
| 27 |
<xsl:for-each select="//record"> |
| 28 |
<xsl:call-template name="record"/> |
| 29 |
</xsl:for-each> |
| 30 |
</record> |
| 31 |
</xsl:otherwise> |
| 32 |
</xsl:choose> |
| 33 |
</xsl:template> |
| 34 |
|
| 35 |
<xsl:template name="record"> |
| 36 |
<xsl:if test="@type"> |
| 37 |
<xsl:attribute name="type"> |
| 38 |
<xsl:value-of select="@type"/> |
| 39 |
</xsl:attribute> |
| 40 |
</xsl:if> |
| 41 |
<xsl:call-template name="transform-leader"/> |
| 42 |
<xsl:call-template name="copy-control"> |
| 43 |
<xsl:with-param name="tag">001</xsl:with-param> |
| 44 |
</xsl:call-template> |
| 45 |
<xsl:call-template name="copy-control"> |
| 46 |
<xsl:with-param name="tag">005</xsl:with-param> |
| 47 |
</xsl:call-template> |
| 48 |
<xsl:call-template name="transform-100"/> |
| 49 |
|
| 50 |
<!-- 200->245 --> |
| 51 |
<xsl:call-template name="transform-datafield"> |
| 52 |
<xsl:with-param name="srcTag">200</xsl:with-param> |
| 53 |
<xsl:with-param name="dstTag">245</xsl:with-param> |
| 54 |
<xsl:with-param name="srcCodes">aefb</xsl:with-param> |
| 55 |
<xsl:with-param name="dstCodes">abch</xsl:with-param> |
| 56 |
</xsl:call-template> |
| 57 |
|
| 58 |
<!-- 210->260 --> |
| 59 |
<xsl:call-template name="transform-datafield"> |
| 60 |
<xsl:with-param name="srcTag">210</xsl:with-param> |
| 61 |
<xsl:with-param name="dstTag">260</xsl:with-param> |
| 62 |
<xsl:with-param name="srcCodes">acd</xsl:with-param> |
| 63 |
<xsl:with-param name="dstCodes">abc</xsl:with-param> |
| 64 |
</xsl:call-template> |
| 65 |
|
| 66 |
<!-- 215->300 --> |
| 67 |
<xsl:call-template name="transform-datafield"> |
| 68 |
<xsl:with-param name="srcTag">215</xsl:with-param> |
| 69 |
<xsl:with-param name="dstTag">300</xsl:with-param> |
| 70 |
<xsl:with-param name="srcCodes">acde</xsl:with-param> |
| 71 |
<xsl:with-param name="dstCodes">abce</xsl:with-param> |
| 72 |
</xsl:call-template> |
| 73 |
|
| 74 |
<!-- 610->653 --> |
| 75 |
<xsl:call-template name="transform-datafield"> |
| 76 |
<xsl:with-param name="srcTag">610</xsl:with-param> |
| 77 |
<xsl:with-param name="dstTag">653</xsl:with-param> |
| 78 |
</xsl:call-template> |
| 79 |
|
| 80 |
<!-- 615->650 --> |
| 81 |
<xsl:call-template name="transform-datafield"> |
| 82 |
<xsl:with-param name="srcTag">615</xsl:with-param> |
| 83 |
<xsl:with-param name="dstTag">650</xsl:with-param> |
| 84 |
<xsl:with-param name="srcCodes">ax</xsl:with-param> |
| 85 |
</xsl:call-template> |
| 86 |
|
| 87 |
<!-- 615->072 --> |
| 88 |
<xsl:call-template name="transform-datafield"> |
| 89 |
<xsl:with-param name="srcTag">615</xsl:with-param> |
| 90 |
<xsl:with-param name="dstTag">072</xsl:with-param> |
| 91 |
<xsl:with-param name="srcCodes">nm</xsl:with-param> |
| 92 |
<xsl:with-param name="dstCodes">ax</xsl:with-param> |
| 93 |
</xsl:call-template> |
| 94 |
|
| 95 |
<!-- 700->100 --> |
| 96 |
<xsl:call-template name="transform-personal-name"> |
| 97 |
<xsl:with-param name="srcTag">700</xsl:with-param> |
| 98 |
<xsl:with-param name="dstTag">100</xsl:with-param> |
| 99 |
</xsl:call-template> |
| 100 |
|
| 101 |
<!-- 701->700 --> |
| 102 |
<xsl:call-template name="transform-personal-name"> |
| 103 |
<xsl:with-param name="srcTag">701</xsl:with-param> |
| 104 |
<xsl:with-param name="dstTag">700</xsl:with-param> |
| 105 |
</xsl:call-template> |
| 106 |
|
| 107 |
<!-- 702->700 --> |
| 108 |
<xsl:call-template name="transform-personal-name"> |
| 109 |
<xsl:with-param name="srcTag">702</xsl:with-param> |
| 110 |
<xsl:with-param name="dstTag">700</xsl:with-param> |
| 111 |
</xsl:call-template> |
| 112 |
</xsl:template> |
| 113 |
|
| 114 |
<xsl:template name="transform-leader"> |
| 115 |
<xsl:variable name="leader" select="leader"/> |
| 116 |
<xsl:variable name="leader05" select="translate(substring($leader,06,1), 'o', 'c')"/> |
| 117 |
<xsl:variable name="leader06" select="translate(substring($leader,07,1), 'hmn', 'aor')"/> |
| 118 |
<xsl:variable name="leader07" select="substring($leader,08,1)"/> |
| 119 |
<xsl:variable name="leader08-16" select="' 22 '"/> |
| 120 |
<xsl:variable name="leader17" select="translate(substring($leader,18,1), '23', '87')"/> |
| 121 |
<xsl:variable name="leader18" select="translate(substring($leader,19,1), ' n', 'i ')"/> |
| 122 |
<xsl:variable name="leader19-23" select="' 4500'"/> |
| 123 |
<leader> |
| 124 |
<xsl:value-of select="concat(' ', $leader05, $leader06, $leader07, $leader08-16, $leader17, $leader18, $leader19-23)"/> |
| 125 |
</leader> |
| 126 |
</xsl:template> |
| 127 |
<xsl:template name="copy-control"> |
| 128 |
<xsl:param name="tag"/> |
| 129 |
<xsl:for-each select="controlfield[@tag=$tag]"> |
| 130 |
<controlfield tag="{$tag}"> |
| 131 |
<xsl:value-of select="text()"/> |
| 132 |
</controlfield> |
| 133 |
</xsl:for-each> |
| 134 |
</xsl:template> |
| 135 |
<xsl:template name="transform-100"> |
| 136 |
<xsl:variable name="source" select="datafield[@tag='100']/subfield[@code='a']"/> |
| 137 |
<xsl:variable name="dest00-05" select="substring($source,03,6)"/> |
| 138 |
<xsl:variable name="dest06" select="translate(substring($source,09,1), 'abcdefghij', 'cdusrqmtpe')"/> |
| 139 |
<xsl:variable name="dest07-14" select="substring($source,10,8)"/> |
| 140 |
<xsl:variable name="dest15-21" select="' '"/> |
| 141 |
<xsl:variable name="dest22" select="translate(substring($source,18,1), 'bcadekmu', 'abjcdeg ')"/> |
| 142 |
<xsl:variable name="dest23-27" select="' '"/> |
| 143 |
<xsl:variable name="dest28" select="translate(substring($source,21,1), 'abcdefghy', 'fsllcizo ')"/> |
| 144 |
<xsl:variable name="dest29-32" select="' '"/> |
| 145 |
<xsl:variable name="dest33" select="substring($source,35,1)"/> |
| 146 |
<xsl:variable name="dest34-37" select="' '"/> |
| 147 |
<xsl:variable name="dest38" select="translate(substring($source,22,1), '01', ' o')"/> |
| 148 |
<xsl:variable name="dest39-40" select="' '"/> |
| 149 |
<controlfield tag="008"> |
| 150 |
<xsl:value-of select="concat($dest00-05, $dest06, $dest07-14, $dest15-21, $dest22, $dest23-27, $dest28, $dest29-32, $dest33, $dest34-37, $dest38, $dest39-40)"/> |
| 151 |
</controlfield> |
| 152 |
</xsl:template> |
| 153 |
<xsl:template name="transform-datafield"> |
| 154 |
<xsl:param name="srcTag"/> |
| 155 |
<xsl:param name="dstTag" select="@srcTag"/> |
| 156 |
<xsl:param name="srcCodes" select="$all-codes"/> |
| 157 |
<xsl:param name="dstCodes" select="$srcCodes"/> |
| 158 |
<xsl:if test="datafield[@tag=$srcTag]/subfield[contains($srcCodes, @code)]"> |
| 159 |
<xsl:for-each select="datafield[@tag=$srcTag]"> |
| 160 |
<datafield tag="{$dstTag}"> |
| 161 |
<xsl:call-template name="copy-indicators"/> |
| 162 |
<xsl:call-template name="transform-subfields"> |
| 163 |
<xsl:with-param name="srcCodes" select="$srcCodes"/> |
| 164 |
<xsl:with-param name="dstCodes" select="$dstCodes"/> |
| 165 |
</xsl:call-template> |
| 166 |
</datafield> |
| 167 |
</xsl:for-each> |
| 168 |
</xsl:if> |
| 169 |
</xsl:template> |
| 170 |
<xsl:template name="transform-personal-name"> |
| 171 |
<xsl:param name="srcTag"/> |
| 172 |
<xsl:param name="dstTag"/> |
| 173 |
|
| 174 |
<xsl:for-each select="datafield[@tag=$srcTag]"> |
| 175 |
<datafield tag="{$dstTag}" ind1="{@ind2}" ind2=""> |
| 176 |
<xsl:call-template name="transform-subfields"> |
| 177 |
<xsl:with-param name="srcCodes" select="'acdfgp4'"/> |
| 178 |
<xsl:with-param name="dstCodes" select="'acbdqu4'"/> |
| 179 |
</xsl:call-template> |
| 180 |
</datafield> |
| 181 |
</xsl:for-each> |
| 182 |
</xsl:template> |
| 183 |
<xsl:template name="copy-indicators"> |
| 184 |
<xsl:attribute name="ind1"> |
| 185 |
<xsl:value-of select="translate(@ind1, '#', '')"/> |
| 186 |
</xsl:attribute> |
| 187 |
<xsl:attribute name="ind2"> |
| 188 |
<xsl:value-of select="translate(@ind2, '#', '')"/> |
| 189 |
</xsl:attribute> |
| 190 |
</xsl:template> |
| 191 |
<xsl:template name="transform-subfields"> |
| 192 |
<xsl:param name="srcCodes" select="$all-codes"/> |
| 193 |
<xsl:param name="dstCodes" select="$srcCodes"/> |
| 194 |
<xsl:for-each select="subfield[contains($srcCodes, @code)]"> |
| 195 |
<subfield code="{translate(@code, $srcCodes, $dstCodes)}"> |
| 196 |
<xsl:value-of select="text()"/> |
| 197 |
</subfield> |
| 198 |
</xsl:for-each> |
| 199 |
</xsl:template> |
| 200 |
|
| 201 |
<xsl:variable name="all-codes">abcdefghijklmnopqrstuvwxyz123456789</xsl:variable> |
| 202 |
</xsl:stylesheet> |