XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (727 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
13.1Mb size Format: txt, pdf, ePub

This function attempts to determine when a couple (identified by a
FamilyRec
) were married. This is done solely so that an individual's partners can be listed in the right order, so the date does not have to be precise. The logic looks complicated, but all it does is find a dated marriage event if it can and otherwise to return the date of birth of the oldest child. The call on
ged:sort-dates()
is a forward reference to a function that we'll see later.

The next group of functions are concerned with formatting and sorting of dates. First a function to convert a date from GEDCOM format into ISO format:



  

  

    

                         regex=“\s*([0-9]+)\s+([A-Z]+)\s+([0-9]+)\s*$”>

      

        

        -

        

                                     ‘JUL’, ‘AUG’, ‘SEP’, ‘OCT’, ‘NOV’, ‘DEC’),

                                     regex-group(2))“ format=“01”/>

        -

        

          

    

  

  


This function only works on a date in standard GEDCOM format
DD
MMM
YYYY
. If you pass it a date in an extended form, such as
BEF
1870
, the stylesheet will fail with a type error.

I've not attempted here to handle the problems of non-Gregorian calendars (which arise all the time with genealogical data). If the GEDCOM date represents a date in the Julian (or
Old Style
) calendar, then in theory it ought to be shifted by 10 or 11 days when converting it to an ISO date, because ISO dates are supposed always to be Gregorian.



   

  


To format a date into the form
2
January
1931
, we first convert the date to standard ISO representation (the
xs:date
type) and then call XSLT's
format-date()
function.

The next two functions are used for sorting dates:



  

  

        if (data($date) instance of StandardDate)

          then string(ged:date-to-ISO($date))

          else substring($date, string-length($date)-3)

        “/>




  

  

    

  


We want to be able to sort standard dates such as
2
JAN
1931
chronologically, but we also want to be able to fit nonstandard dates such as
BEF
1870
into the sequence as best we can. To achieve this, I've chosen a sort key that uses the ISO conversion of the date in the case of standard dates (for example,
1931-01-02
, and that uses the last four characters otherwise.

Other books

Easy Target by Kay Thomas
Lastnight by Stephen Leather
Stone Guardian by Monsch, Danielle
A Curse Unbroken by Cecy Robson
Gone Fishin' by Walter Mosley
One Good Turn by Kate Atkinson
Cowboy at Midnight by Ann Major
One Magic Moment by Lynn Kurland
Jack Kane and the Statue of Liberty by Michell Plested, J. R. Murdock