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

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

I left out the part of the
match=“specref”
template that handles the error case. Generally, this stylesheet does not do much validation of this kind, and it would probably be a good thing if it did more. Many errors in source documents, if they pass the checks performed by the DTD, are detected only because the HTML that's generated turns out to be invalid.

    

      

        Unsupported specref to 

        

         [

        

        

         (Contact stylesheet maintainer).

      

      

        

          

            

              

            

          

          ???

        

      

    

  


Setting Out the Production Rules

Now we get to a more interesting area. The XML Recommendation contains syntax production rules, and these are marked up in some detail. A sequence of production rules is contained within a

element, and each rule is a

element. Here is an example of a

that contains a single production rule:


   Document

   

      document

      

         prolog

         element

         Misc*

      

   


This is of course the production rule for an XML document, which appears in the specification as shown in
Figure 18-4
.

In some cases the production rules within a

are grouped into

elements, but this grouping is ignored in the output.

Here are the top-level template rules:





  

    

  




  

    

  







  

    

      select=“lhs |

              rhs[preceding-sibling::*[1][name()!=‘lhs’]] |

              com[preceding-sibling::*[1][name()!=‘rhs’]] |

              constraint[preceding-sibling::*[1][name()!=‘rhs’]] |

              vc[preceding-sibling::*[1][name()!=‘rhs’]] |

              wfc[preceding-sibling::*[1][name()!=‘rhs’]]”/>

  



  

    select=“lhs |

            rhs[preceding-sibling::*[1][name()!=‘lhs’]] |

            com[preceding-sibling::*[1][name()!=‘rhs’]] |

            constraint[preceding-sibling::*[1][name()!=‘rhs’]] |

            vc[preceding-sibling::*[1][name()!=‘rhs’]] |

            wfc[preceding-sibling::*[1][name()!=‘rhs’]]”/>


To understand this, let's first ignore the horrendous
select
expression that appears in the last two rules.

  • The rule for the

    element processes the

    element to produce a heading and then outputs an HTML table, whose contents are generated by processing all the

    and

    elements contained in the

    .
  • The rule also allows for a

    to contain

    elements. However, the document we're working with doesn't contain any, so we can ignore this.
  • The rules are being rather pedantic by ensuring that the rows of the table are always contained in a

    element. In practice, Web browsers don't insist on a

    being present, and many HTML authors don't bother writing one, but technically the HTML specification requires it, and the W3C takes great pains to make sure that the documents it publishes are valid HTML. This means that when there is a

    present, the

    is generated at the level of the

    ; when there is a

    that is not contained in a

    (that is, it is contained directly in the

    ), then the

    is generated when processing the

    element; but when a

    is contained in a

    , no additional

    is produced.

Now let's look at the monster
select
expression. A production rule (

) has one left-hand side (

), one or more right-hand sides (

), and one or more annotations (

,

, or

). A

element is used to refer to a validation constraint, a

element to refer to a well-formedness constraint, and a

element to refer to a comment. The XML specification does not use

elements, so we can ignore those.

A rule with one

element, two

elements, and three

annotations would be laid out in an HTML table like this:

As the comment says, the
select
expression is processing the children of the

element that start a new row: here,
lhs1
,
rhs2
,
wfc2
, and
wfc3
. More precisely, the selected elements include every

element, any

element that is not immediately preceded by an

element, and any

,

, or

element that is not immediately preceded by an

element. So, this template selects the elements that will start a new row, and calls

to process them.

We'll now look at the template rules that will match these elements. First, the

:



  

    

      

        

          diff-

          

        

      

      

        

      

      

         

    

    

      

        

          diff-

          

        

      

      

    

    

      

        

          diff-

          

        

      

         ::=   

    

    

  


Other books

Princess of the Sword by Lynn Kurland
Enough About Love by Herve Le Tellier
The Meeting Point by Austin Clarke
Coal Black Horse by Robert Olmstead
Almost a Scandal by Elizabeth Essex
Aura by Abraham, M.A.
Fatal Venture by Freeman Wills Crofts
Gather the Bones by Alison Stuart