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

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

There are some elements in the XML that are not rendered in the HTML at all, for example:


  


I generally write empty template rules using the shorter style:


but one can't criticize this writer for adding a comment to make the intention clear.

The XML specification represents tables in exactly the same way as HTML, except that some additional attributes are permitted. So the template rule's job is essentially to copy the element while adjusting those attributes:




  

    

      

      

        

          

            

          

        

        

          

        

        

          

            

          

        

      

    

    

  


I think I would have been inclined to handle these attributes using template rules, especially as we've already seen the same code to rename a
role
attribute as a
class
attribute, elsewhere in the stylesheet. Instead of

and the big

instruction, I would write

, with the three template rules:


   




  


In a previous version of the stylesheet, the above rule was also used to handle

and

elements. These have now been extracted into a separate rule:


    

      

        

        

          

            

              

            

          

          

          

          

          

            

          

        

      

      

    


Careful inspection reveals that the only difference is the handling of the
colspan
and
rowspan
attributes; if the original template had been restructured to apply templates to the attributes, this modification could have been handled without duplicating the logic by defining a few new rules:





This is a good demonstration of how the “push” style of processing using

can give stylesheets greater potential for change than the “pull” style using

.

Producing Lists

The DTD for these documents provides a number of ways of defining lists. For example, an ordered list looks like this:

The design goals for XML are:



XML shall be straightforwardly usable over the

         Internet.


XML shall support a wide variety of applications.


XML shall be compatible with SGML.


It shall be easy to write programs which process XML

         documents.


The number of optional features in XML is to be kept

             to the absolute minimum, ideally zero.


XML documents should be human-legible and reasonably

         clear.


The XML design should be prepared quickly.


The design of XML shall be formal and concise.


XML documents shall be easy to create.


Terseness in XML markup is of minimal importance.



The rule for ordered lists aims to decide automatically what kind of numbering to apply to nested levels of list:
1,2,3
for the outermost level,
a,b,c
for the second level,
i,ii,iii
for the third level, and so on.



  

    

  

  

    

  



    

    

      ar

      la

      lr

      ua

      ur

    


Previous versions of the stylesheet used an incredibly verbose recursive template to achieve the same effect; it would be nice to think that my criticism in earlier editions of the book influenced the rewrite! It could still be made simpler in XSLT 2.0. Given that
list.numeration
is only called from one place, the template rule could be written as:



   

  

                select=“(‘ar’, ‘la’, ‘lr’, ‘ua’, ‘ur’)[$depth mod 5 + 1]”/>

  

    

  


Other books

The Price of Success by Maya Blake
The Consequence by Karin Tabke
Friends With Benefits by Alaina Marks
Cherry Pie by Samantha Kane
Embrace Me by Rebecca Turley, Sally Goodwin, Elizabeth Simonton, Jo Matthews
Definitely Naughty by Jo Leigh
Tempted by Rebecca Zanetti
1514642093 (R) by Amanda Dick
Evil Librarian by Michelle Knudsen
All Roads Lead to Austen by Amy Elizabeth Smith