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
5.73Mb size Format: txt, pdf, ePub
ads

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.

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

Other books

One Dom at a Time by Holly Roberts
Paris is a Bitch by Barry Eisler
Someone Elses Daughter by Jack Norman
Figure it Out For Yourself by James Hadley Chase
Summer Ruins by Leigh, Trisha
Scream Catcher by Vincent Zandri
Donovan's Woman by Amanda Ashley
Did Not Finish by Simon Wood
The Moses Stone by James Becker