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

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

The next named template is used to display the list of events for an individual, such as birth, marriage and death.



  

                as=     “schema-element(IndividualRec)”

                select= “.”/>

  

        

        

        


        

            

              :

            

            

                                 mode=“link”/>

            

        

        

            Date: 

            

        

        

            Place: 

            

        

        


        

            


        

  


The events are located using the
ged:events-for-person()
function, and they are presented in an attempt at date order, achieved by calling the
ged:date-sort-key()
function that we saw earlier.

For each event the template displays the name of the event (in title case, for example
Birth
), the list of participants other than the subject of this page, the date and place of the event, and any notes recorded about the event. In each case this is done by applying the appropriate template rules.

The only part of the HTML display that remains is the right-hand panel, where we show information about a person's partner(s) and children. If multiple partners are recorded for an individual, we use headings such as “Partner 1”, “Partner 2”; if there is only one, we omit the number.

The template looks like this:


  

                as=     “element(IndividualRec)”

                select= “.”/>

  

                as=     “element(FamilyRec)*”

                select= “ged:families-of-spouse(.)”/>

  

    

    

                  as=     “element(IndividualRec)?”

                  select= “key(‘indi’, element(*, ParentType)/Link/@Ref)

                             except $subject”/>

    

                  as=     “xs:integer?”

                  select= “position()[count($partnerships) ne 1]”/>

    

      Partner 

      


    

    

      Children:

      


        

          

          

                                 Link/@Ref/key(‘indi’,.)/ged:birth-date(.))”/>

          

                        as=     “element(IndividualRec)”

                        select= “Link/@Ref/key(‘indi’,.)”/>

          

           

          

        

      


    

  


As before, we try to list the partners in chronological order, based on the year of marriage. If this isn't known, there's not much we can do about it (I could have tried to use the

field, but it's not present in the data we are using). For each partnership, we list the partner's name, as a hyperlink, and then the children's names, again as hyperlinks. The children are found from the

fields of the

record, and they are listed in order of year of birth where this is known.

The expression
position()[count($partnerships) ne 1]
merits some explanation. It returns the value of
position()
, unless the number of partnerships is one, in which case it returns an empty sequence. The effect is that when there is only one partner we don't output “Partner 1” (which is not only inelegant, but might be thought presumptive!)

The next group of template rules is used to create the HTML hyperlinks:


   

     

        

     

     

   



     

    

     



    


The
make-href
template is the only place where the form of a link is defined: in this case it consists of a relative URL reference to another HTML file, with a filename based on the individual's
Id
attribute, for example
I27.html
. This has been very deliberately isolated into a template all of its own, for reasons that will become clear later.

The stylesheet ends with the template rules for formatting dates, places, and notes:


  

    

      

    

  

  


The above rule sorts the parts of a date by the value of their
Level
attribute, and then outputs them in a comma-separated list. Note that we no longer need to specify that this is a numeric sort, the system can work this out from the schema.


  



  


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

Other books

Empire of Man 01 - March Upcountry by David Weber, John Ringo
Bad Yeti by Carrie Harris
The Color Purple by Alice Walker
The Seahorse by Michael Aye
The Opposite of Invisible by Liz Gallagher
Prince Voronov's Virgin by Lynn Raye Harris
Spellscribed: Conviction by Kristopher Cruz
Friends and Lovers by Helen Macinnes