updateCSL.xsl (19695B)
1 <xsl:stylesheet xmlns:cs="http://purl.org/net/xbiblio/csl" xmlns="http://purl.org/net/xbiblio/csl" 2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" exclude-result-prefixes="cs"> 3 4 <xsl:output indent="yes" method="xml" encoding="utf-8"/> 5 <xsl:strip-space elements="*"/> 6 7 <!-- * xml:lang is no longer allowed on cs:style to eliminate confusion with 8 the default-locale attribute. If xml:lang was set, its value is 9 transferred to the default-locale attribute. 10 * cs:style now indicates CSL version compatibility via the version 11 attribute. --> 12 <xsl:template match="/cs:style"> 13 <xsl:copy> 14 <xsl:copy-of select="@*[not(name()='xml:lang')]"/> 15 <xsl:choose> 16 <xsl:when test="@xml:lang and not(@xml:lang='en' or @xml:lang='en-US' or @xml:lang='en-us')"> 17 <xsl:attribute name="default-locale"> 18 <xsl:value-of select="@xml:lang"/> 19 </xsl:attribute> 20 </xsl:when> 21 </xsl:choose> 22 <xsl:attribute name="version">1.0</xsl:attribute> 23 <xsl:attribute name="demote-non-dropping-particle">sort-only</xsl:attribute> 24 <xsl:apply-templates/> 25 </xsl:copy> 26 </xsl:template> 27 28 <!-- Elements that themselves can be copied verbatim but whose child nodes 29 might require modification. --> 30 <xsl:template 31 match="cs:choose|cs:else|cs:info|cs:names|cs:substitute|cs:macro|cs:layout"> 32 <xsl:copy> 33 <xsl:copy-of select="@*"/> 34 <xsl:apply-templates/> 35 </xsl:copy> 36 </xsl:template> 37 38 <!-- Elements that can be copied verbatim together with any child nodes. --> 39 <xsl:template match="cs:sort|cs:number|comment()"> 40 <xsl:copy-of select="."/> 41 </xsl:template> 42 43 <!-- Child elements of cs:info that can be copied verbatim. --> 44 <xsl:template 45 match="cs:author|cs:contributor|cs:id|cs:issn|cs:published|cs:rights|cs:source|cs:summary|cs:title|cs:updated"> 46 <xsl:copy-of select="."/> 47 </xsl:template> 48 49 <!-- For the rel attribute on cs:link, "documentation" will be used instead of 50 "homepage", and "source" has been renamed to "independent-parent". The 51 URL of a dependent style is now accompanied with a rel value of "self". --> 52 <xsl:template match="cs:link"> 53 <xsl:variable name="rel-value"> 54 <xsl:choose> 55 <xsl:when test="@rel='documentation' or @rel='homepage'">documentation</xsl:when> 56 <xsl:when test="@rel='template'">template</xsl:when> 57 <xsl:when test="@rel='source'">independent-parent</xsl:when> 58 <xsl:otherwise>self</xsl:otherwise> 59 </xsl:choose> 60 </xsl:variable> 61 <xsl:copy> 62 <xsl:attribute name="href"> 63 <xsl:value-of select="@href"/> 64 </xsl:attribute> 65 <xsl:attribute name="rel"> 66 <xsl:value-of select="$rel-value"/> 67 </xsl:attribute> 68 </xsl:copy> 69 </xsl:template> 70 71 <!-- The citation-format and field attributes have replaced the term attribute 72 on cs:category, and the "in-text" category has been removed. Styles with 73 the "in-text" category are assigned the "numeric" citation-format if the 74 "citation-number" variable is used in citations, and the "author-date" 75 format in all other cases. --> 76 <xsl:template match="cs:category"> 77 <xsl:choose> 78 <xsl:when test="@term='in-text'"> 79 <xsl:choose> 80 <xsl:when test="/cs:style/cs:citation//cs:text[@variable='citation-number']"> 81 <xsl:copy> 82 <xsl:attribute name="citation-format">numeric</xsl:attribute> 83 </xsl:copy> 84 </xsl:when> 85 <xsl:otherwise> 86 <xsl:copy> 87 <xsl:attribute name="citation-format">author-date</xsl:attribute> 88 </xsl:copy> 89 </xsl:otherwise> 90 </xsl:choose> 91 </xsl:when> 92 <xsl:when test="@term='author-date' or @term='numeric' or @term='label' or @term='note'"> 93 <xsl:copy> 94 <xsl:attribute name="citation-format"> 95 <xsl:value-of select="@term"/> 96 </xsl:attribute> 97 </xsl:copy> 98 </xsl:when> 99 <xsl:otherwise> 100 <xsl:copy> 101 <xsl:attribute name="field"> 102 <xsl:value-of select="@term"/> 103 </xsl:attribute> 104 </xsl:copy> 105 </xsl:otherwise> 106 </xsl:choose> 107 </xsl:template> 108 109 <!-- The hierarchy cs:terms/cs:locale/cs:term has been replaced by 110 cs:locale/cs:terms/cs:term. --> 111 <xsl:template match="cs:terms/cs:locale"> 112 <xsl:copy> 113 <xsl:copy-of select="@*"/> 114 <xsl:element name="terms"> 115 <xsl:copy-of select="cs:term"/> 116 </xsl:element> 117 </xsl:copy> 118 </xsl:template> 119 120 <!-- Citation-specific CSL options are now set as attributes on cs:citation, 121 instead of via cs:option elements. --> 122 <xsl:template match="cs:citation"> 123 <xsl:copy> 124 <xsl:for-each select="cs:option"> 125 <xsl:attribute name="{@name}"> 126 <xsl:value-of select="@value"/> 127 </xsl:attribute> 128 </xsl:for-each> 129 <xsl:apply-templates select="cs:layout|cs:sort"/> 130 </xsl:copy> 131 </xsl:template> 132 133 <!-- * Bibliography-specific CSL options are now set as attributes on 134 cs:bibliography, instead of via cs:option elements. 135 * second-field-align now uses the value "flush" instead of "true". --> 136 <xsl:template match="cs:bibliography"> 137 <xsl:copy> 138 <xsl:for-each select="cs:option"> 139 <xsl:choose> 140 <xsl:when test="@name='second-field-align' and @value='true'"> 141 <xsl:attribute name="second-field-align">flush</xsl:attribute> 142 </xsl:when> 143 <xsl:otherwise> 144 <xsl:attribute name="{@name}"> 145 <xsl:value-of select="@value"/> 146 </xsl:attribute> 147 </xsl:otherwise> 148 </xsl:choose> 149 </xsl:for-each> 150 <xsl:apply-templates select="cs:layout|cs:sort"/> 151 </xsl:copy> 152 </xsl:template> 153 154 <!-- CSL 1.0 eliminates item type fallback behavior in conditionals 155 ("article", "book" and "chapter" used to be type archetypes, e.g. 156 "article-journal" would be a subtype of "article", see 157 http://docs.google.com/View?id=dg6h9k72_64hzmsmqgb). For the conversion, 158 each archetype is replaced by all subtypes of that archetype (while 159 making sure that "song" is only present once in the attribute string, as 160 "song" is a subtype of both "article" and "book"). If an archetype is 161 replaced by its subtypes, the match attribute is set to "any", unless 162 match was set to "none". This is done as "type='chapter' match='all'" can 163 test true, but "type='chapter paper-conference' match='all' can not (each 164 item is of a single type). cs:if and cs:if-else elements that, in 165 addition to the type conditional, test with match="all" (the default 166 attribute value) and carry additional conditionals are split into a 167 nested conditional (an example of this case is given at 168 http://forums.zotero.org/discussion/11960/item-type-testing-in-csl-10-and-fallbacks/#Comment_58392 169 ). --> 170 <xsl:template match="cs:if|cs:else-if"> 171 <xsl:copy> 172 <xsl:choose> 173 <xsl:when test="contains(@type,'book') or (contains(@type,'article') and not(contains(@type,'article-'))) or contains(@type,'chapter')"> 174 <xsl:choose> 175 <xsl:when test="(not(@match='any') and not(@match='none')) and (@variable or @is-numeric or @position or @disambiguate)"> 176 <xsl:call-template name="fallback-replacement"/> 177 <xsl:attribute name="match">any</xsl:attribute> 178 <xsl:element name="choose"> 179 <xsl:element name="if"> 180 <xsl:copy-of select="@*[not(name()='type')]"/> 181 <xsl:apply-templates/> 182 </xsl:element> 183 </xsl:element> 184 </xsl:when> 185 <xsl:otherwise> 186 <xsl:copy-of select="@*"/> 187 <xsl:call-template name="fallback-replacement"/> 188 <xsl:if test="not(@match='none')"> 189 <xsl:attribute name="match">any</xsl:attribute> 190 </xsl:if> 191 <xsl:apply-templates/> 192 </xsl:otherwise> 193 </xsl:choose> 194 </xsl:when> 195 <xsl:otherwise> 196 <xsl:copy-of select="@*"/> 197 <xsl:apply-templates/> 198 </xsl:otherwise> 199 </xsl:choose> 200 </xsl:copy> 201 </xsl:template> 202 203 <xsl:template name="fallback-replacement"> 204 <xsl:choose> 205 <xsl:when test="contains(@type,'book')"> 206 <xsl:attribute name="type"> 207 <xsl:call-template name="book-sans-space"/> 208 <xsl:call-template name="article"/> 209 <xsl:call-template name="chapter"/> 210 </xsl:attribute> 211 </xsl:when> 212 <xsl:when test="contains(@type,'article') and not(contains(@type,'article-'))"> 213 <xsl:attribute name="type"> 214 <xsl:call-template name="article-sans-space"/> 215 <xsl:call-template name="book"/> 216 <xsl:call-template name="chapter"/> 217 </xsl:attribute> 218 </xsl:when> 219 <xsl:when test="contains(@type,'chapter')"> 220 <xsl:attribute name="type"> 221 <xsl:call-template name="chapter-sans-space"/> 222 <xsl:call-template name="article"/> 223 <xsl:call-template name="book"/> 224 </xsl:attribute> 225 </xsl:when> 226 </xsl:choose> 227 </xsl:template> 228 229 <xsl:template name="book-sans-space"> 230 <xsl:text>bill book graphic legal_case motion_picture report song</xsl:text> 231 </xsl:template> 232 233 <xsl:template name="article-sans-space"> 234 <xsl:choose> 235 <xsl:when test="contains(@type,'article') and not(contains(@type,'article-')) and contains(@type,'book')">article-journal article-magazine article-newspaper broadcast interview manuscript map patent personal_communication speech thesis webpage</xsl:when> 236 <xsl:when test="contains(@type,'article') and not(contains(@type,'article-'))">article-journal article-magazine article-newspaper broadcast interview manuscript map patent personal_communication song speech thesis webpage</xsl:when> 237 </xsl:choose> 238 </xsl:template> 239 240 <xsl:template name="chapter-sans-space"> 241 <xsl:text>chapter paper-conference</xsl:text> 242 </xsl:template> 243 244 <xsl:template name="book"> 245 <xsl:choose> 246 <xsl:when test="contains(@type,'book')"> bill book graphic legal_case motion_picture report song</xsl:when> 247 <xsl:otherwise> 248 <xsl:if test="contains(@type,'bill')"> bill</xsl:if> 249 <xsl:if test="contains(@type,'graphic')"> graphic</xsl:if> 250 <xsl:if test="contains(@type,'legal_case')"> legal_case</xsl:if> 251 <xsl:if test="contains(@type,'motion_picture')"> motion_picture</xsl:if> 252 <xsl:if test="contains(@type,'report')"> report</xsl:if> 253 <xsl:if test="contains(@type,'song')"> song</xsl:if> 254 </xsl:otherwise> 255 </xsl:choose> 256 </xsl:template> 257 258 <xsl:template name="article"> 259 <xsl:choose> 260 <xsl:when test="contains(@type,'article') and not(contains(@type,'article-')) and contains(@type,'book')"> article-journal article-magazine article-newspaper broadcast interview manuscript map patent personal_communication speech thesis webpage</xsl:when> 261 <xsl:when test="contains(@type,'article') and not(contains(@type,'article-'))"> article-journal article-magazine article-newspaper broadcast interview manuscript map patent personal_communication song speech thesis webpage</xsl:when> 262 <xsl:otherwise> 263 <xsl:if test="contains(@type,'article-journal')"> article-journal</xsl:if> 264 <xsl:if test="contains(@type,'article-magazine')"> article-magazine</xsl:if> 265 <xsl:if test="contains(@type,'article-newspaper')"> article-newspaper</xsl:if> 266 <xsl:if test="contains(@type,'broadcast')"> broadcast</xsl:if> 267 <xsl:if test="contains(@type,'interview')"> interview</xsl:if> 268 <xsl:if test="contains(@type,'manuscript')"> manuscript</xsl:if> 269 <xsl:if test="contains(@type,'map')"> map</xsl:if> 270 <xsl:if test="contains(@type,'patent')"> patent</xsl:if> 271 <xsl:if test="contains(@type,'personal_communication')"> personal_communication</xsl:if> 272 <xsl:if test="contains(@type,'speech')"> speech</xsl:if> 273 <xsl:if test="contains(@type,'thesis')"> thesis</xsl:if> 274 <xsl:if test="contains(@type,'map')"> map</xsl:if> 275 <xsl:if test="contains(@type,'webpage')"> webpage</xsl:if> 276 </xsl:otherwise> 277 </xsl:choose> 278 </xsl:template> 279 280 <xsl:template name="chapter"> 281 <xsl:choose> 282 <xsl:when test="contains(@type,'chapter')"> chapter paper-conference</xsl:when> 283 <xsl:otherwise> 284 <xsl:if test="contains(@type,'paper-conference')"> paper-conference</xsl:if> 285 </xsl:otherwise> 286 </xsl:choose> 287 </xsl:template> 288 289 <!-- * The class attribute on cs:group has been removed in favor of the 290 display attribute. 291 * The " by " prefix on cs:group is removed if the element encloses a 292 cs:names element calling the container-author variable and including a 293 label. This is done to prevent duplication of "by" as a result of the 294 new verb-short container-author term in CSL 1.0 locale files. --> 295 <xsl:template match="cs:group"> 296 <xsl:copy> 297 <xsl:choose> 298 <xsl:when test="@prefix=' by ' and cs:names/@variable='container-author' and cs:names/cs:label"> 299 <xsl:copy-of select="@*[not(name()='class' or name()='prefix')]"/> 300 </xsl:when> 301 <xsl:otherwise> 302 <xsl:copy-of select="@*[not(name()='class')]"/> 303 </xsl:otherwise> 304 </xsl:choose> 305 <xsl:apply-templates/> 306 </xsl:copy> 307 </xsl:template> 308 309 <!-- * The text-case attribute can no longer be used on cs:name. In cases 310 where text-case was used on cs:name, the attribute and its value are 311 transferred to the "family" and "given" cs:name-part children. 312 * The Zotero and Mendeley CSL 0.8.1 processors ignored name-as-sort-order 313 when sort-separator was not set. In CSL 1.0, name-as-sort-order always 314 takes effect, with a default value of ", " for sort-separator. To 315 correct for this change in behavior, the name-as-sort-order attribute 316 is dropped from cs:name when sort-separator was absent. --> 317 <xsl:template match="cs:name"> 318 <xsl:copy> 319 <xsl:choose> 320 <xsl:when test="@name-as-sort-order and not(@sort-separator)"> 321 <xsl:copy-of select="@*[not(name()='text-case' or name()='name-as-sort-order')]"/> 322 </xsl:when> 323 <xsl:otherwise> 324 <xsl:copy-of select="@*[not(name()='text-case')]"/> 325 </xsl:otherwise> 326 </xsl:choose> 327 <xsl:choose> 328 <xsl:when test="@text-case"> 329 <xsl:element name="name-part"> 330 <xsl:attribute name="name">family</xsl:attribute> 331 <xsl:attribute name="text-case"> 332 <xsl:value-of select="@text-case"/> 333 </xsl:attribute> 334 </xsl:element> 335 <xsl:element name="name-part"> 336 <xsl:attribute name="name">given</xsl:attribute> 337 <xsl:attribute name="text-case"> 338 <xsl:value-of select="@text-case"/> 339 </xsl:attribute> 340 </xsl:element> 341 </xsl:when> 342 </xsl:choose> 343 </xsl:copy> 344 </xsl:template> 345 346 <!-- * In CSL 1.0, abbreviated terms are defined with periods, if applicable, 347 and the include-period attribute has replaced the strip-periods 348 attribute. For the conversion, strip-periods is set to "true" for any 349 cs:label element with form="short" or "verb-short", except when 350 include-period was set to "true". 351 * plural on cs:label now uses "always"/"never" instead of "true"/"false". --> 352 <xsl:template match="cs:label"> 353 <xsl:copy> 354 <xsl:copy-of select="@*[not(name()='include-period')]"/> 355 <xsl:choose> 356 <xsl:when test="(@form='short' or @form='verb-short') and not(@include-period='true')"> 357 <xsl:attribute name="strip-periods">true</xsl:attribute> 358 </xsl:when> 359 </xsl:choose> 360 <xsl:choose> 361 <xsl:when test="@plural='false'"> 362 <xsl:attribute name="plural">never</xsl:attribute> 363 </xsl:when> 364 <xsl:when test="@plural='true'"> 365 <xsl:attribute name="plural">always</xsl:attribute> 366 </xsl:when> 367 </xsl:choose> 368 </xsl:copy> 369 </xsl:template> 370 371 <!-- The "event" date variable has been renamed to "event-date" to eliminate 372 the name conflict with the 'standard' "event" variable. --> 373 <xsl:template match="cs:date"> 374 <xsl:copy> 375 <xsl:copy-of select="@*"/> 376 <xsl:choose> 377 <xsl:when test="@variable='event'"> 378 <xsl:attribute name="variable">event-date</xsl:attribute> 379 </xsl:when> 380 </xsl:choose> 381 <xsl:apply-templates/> 382 </xsl:copy> 383 </xsl:template> 384 385 <!-- In CSL 1.0, abbreviated terms are defined with periods, if applicable, 386 and the include-period attribute has replaced the strip-periods 387 attribute. For the conversion, strip-periods is set to "true" for any 388 "month" cs:date-part element with form="short", except when 389 include-period was set to "true". --> 390 <xsl:template match="cs:date-part"> 391 <xsl:choose> 392 <xsl:when test="@name='year' or @name='month' or @name='day'"> 393 <xsl:copy> 394 <xsl:copy-of select="@*[not(name()='include-period')]"/> 395 <xsl:choose> 396 <xsl:when 397 test="@form='short' and @name='month' and not(@include-period='true')"> 398 <xsl:attribute name="strip-periods">true</xsl:attribute> 399 </xsl:when> 400 </xsl:choose> 401 </xsl:copy> 402 </xsl:when> 403 </xsl:choose> 404 </xsl:template> 405 406 <!-- * In CSL 1.0, abbreviated terms are defined with periods, if applicable, 407 and the include-period attribute has replaced the strip-periods 408 attribute. For the conversion, strip-periods is set to "true" for any 409 cs:text element with form="short" or "verb-short", except when 410 include-period was set to "true". 411 * A special case is the "ibid" term. "ibid" is not defined as a 412 short-form term, but is an abbreviation, and should carry a period 413 ("ibid."). This period, absent in CSL 0.8 locale files, will be 414 included in CSL 1.0 locale files. To prevent double periods, suffix="." 415 will be removed from any cs:text element calling the "ibid" term. 416 * The CSL 0.8 en-US locale file only included the "long" form of the 417 "no date" term, with a value of "n.d.". In the CSL 1.0 locale file, the 418 value has been changed to "no date", and a "short" form ("n.d.") has 419 been introduced. For the conversion, any cs:text element that called 420 the "long" form of the "no date" term will now call the "short" form, 421 unless the "long" form had been redefined in the style. --> 422 <xsl:template match="cs:text"> 423 <xsl:choose> 424 <xsl:when test="@term='ibid' and @suffix='.'"> 425 <xsl:copy> 426 <xsl:copy-of select="@*[not(name()='suffix')]"/> 427 </xsl:copy> 428 </xsl:when> 429 <xsl:otherwise> 430 <xsl:copy> 431 <xsl:copy-of select="@*[not(name()='include-period')]"/> 432 <xsl:choose> 433 <xsl:when 434 test="(@form='short' or @form='verb-short') and not(@include-period='true' or @term='no date') and @term"> 435 <xsl:attribute name="strip-periods">true</xsl:attribute> 436 </xsl:when> 437 </xsl:choose> 438 <xsl:choose> 439 <xsl:when test="@term='no date' and not(/cs:style/cs:terms/cs:locale/cs:term/@name='no date')"> 440 <xsl:attribute name="form">short</xsl:attribute> 441 </xsl:when> 442 </xsl:choose> 443 </xsl:copy> 444 </xsl:otherwise> 445 </xsl:choose> 446 </xsl:template> 447 448 </xsl:stylesheet>