Issue #12 new

sort_ConditionalMacroDates.txt

Benjamin Geißler
created an issue

I think the <text variable="title"/> has to be removed from the <macro name="issued-date">, because otherwise the result of the macro will always start with the title (Book 1, Book 2, Book 3) and so sort it through the value of the title and not the date.

Comments (12)

  1. Frank Bennett

    The behaviour is documented here:

    http://citationstyles.org/downloads/specification.html#sorting-macros

    If a macro used as a key contains a date after evaluation of conditionals, everything but the date is discarded, and the value is normalized as a sort key.

    The sort keys generated in citeproc-js look like this:

    GROUP "run.sort_ConditionalMacroDates" has 1 test to run
    keystring: (Y20021225Y00000000) string bibliography_sort
    keystring: (Y20020000Y00000000) string bibliography_sort
    keystring: (Y20021025Y00000000) string bibliography_sort
    

    (In checking this I noticed that the year-only key was coming out wrong, actually, as Y200200Y000000, although the test result was correct. I've just fixed that in the processor.)

    To address the point of confusion indicated by Rintze, I've changed "Book" to "Title" in the test.

  2. Rintze Zelle

    "If a macro used as a key contains a date after evaluation of conditionals, everything but the date is discarded"

    Where does the spec say that, specifically?

  3. Frank Bennett

    The language I had in mind is "In contrast, macros return only those date-parts that would otherwise be rendered (respecting the value of the date-parts attribute for localized dates, or the listing of cs:date-part elements for non-localized dates)."

    It doesn't say anything about discarding other output, but that does need to happen to get a meaningful sort key. Would it be possible to add that to the description?

  4. Rintze Zelle

    If a macro used as a key contains a date after evaluation of conditionals, everything but the date is discarded, and the value is normalized as a sort key.

    Should that read as

    "If a macro used as a key contains one or more dates after evaluation of conditionals, everything but the first date is discarded, and its value is normalized as a sort key."

    ?

  5. Frank Bennett

    If the test is run with a processor that does not discard non-date elements in the macro, it will fail with:

    <div class="csl-bib-body">
      <div class="csl-entry">Title 1</div>
      <div class="csl-entry">Title 2</div>
      <div class="csl-entry">Title 3</div>
    </div>
    

    If the title were left out of the macro, it should still fail with a result in input order, but the inclusion of the title makes failure more certain.

  6. Frank Bennett

    I found some earlier mail. It was done in the summer of 2011, prompted by problems with sorting in APA. It allows a macro to choose which date elements to include in the date sort key depending on conditions (year for books, year-month-day for newspaper articles, say).

  7. Rintze Zelle

    It allows a macro to choose which date elements to include in the date sort key depending on conditions

    That would only require that the conditional is evaluated, not that non-date elements are discarded.

  8. Frank Bennett

    Sorry, that was misleading. citeproc-js was extracting dates from macros before that exchange; the change at that point was indeed only to evaluate conditionals.

    The reason for extracting dates is that they need a key of a different type. That will be true regardless of the implementation. In citeproc-js, date keys are specially formatted strings, so they could be mixed with text content, but the effect on sort results would be unpredictable and opaque.

    A cleaner approach to the coding would probably cast date sort keys as a pair of integers or date objects (to handle date ranges). In that case also, text content would need to be excluded.

  9. Log in to comment