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

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


  

                lhs |

                rhs[preceding-sibling::*[1][not(self::lhs)]] |

                com[preceding-sibling::*[1][not(self::rhs)]] |

                constraint[preceding-sibling::*[1][not(self::rhs)]] |

                vc[preceding-sibling::*[1][not(self::rhs)] |

                wfc[preceding-sibling::*[1][not(self::rhs)]]”>

     

        

        

     

  


Now, we define a set of simple template rules to produce the empty cells in each row, depending on the type of the first element in the row:



   



   


And finally we provide one template rule for each kind of element, which simply outputs the content of the appropriate cells in the table. There is no longer any need for it to worry about what comes afterwards: that's taken care of by the iteration in the master
show.prod
template.


   

      

      

         

      

      

         

   

   

      

      

   

   

      

         ::=   

   



   

      

      

   



   

      

      

          

             

                

             

          

          [VC: 

          

          ]

      

   


As before, I left out the logic for

,

, and

elements, to avoid repetition. But I think you'll agree that the

instruction, while still requiring some thought, makes this tricky problem a lot easier to tackle than it was in XSLT 1.0.

For completeness, here is the
show.diff
template:


  

      

                      select=“concat(‘diff-’, ancestor-or-self::*/@diff)”/>

  


Finally, there's one other question that needs to be asked: Is it appropriate to be generating HTML


markup here at all? Good practice dictates that HTML tables should be used only for tabular information, and not to achieve manual control over the layout of the output page. I think one could argue this example either way. Certainly, use of CSS positioning would be an alternative worth considering.

Overlay Stylesheets

As I mentioned at the start,
xmlspec.xsl
is just one module in the stylesheet used to format the XML Recommendation. The
xmlspec.xsl
module is imported by
diffspec.xsl
, which in turn is imported by
REC-xml.xsl
. We will now take a look at these two “overlays”, which modify the behavior of the base stylesheet.

diffspec.xsl

This stylesheet module is used to do change marking for documents such as the XML Recommendation. You can see an example of its output at
http://www.w3.org/TR/REC-xml/REC-xml-20060816-review.html
where it is used to show the changes between the third and fourth editions of the Recommendation.

For some of the W3C specifications, editors maintain change markup by hand as they make changes to documents. Typically, the markup looks like this:


  (Of strings or names:) Two strings or names being compared

  MUST be

  are

  identical. …


In other cases, the change markup is generated automatically by running a comparison program (written in XSLT, naturally) against the two documents. I don't know which approach was used for the XML Recommendation, but the markup is the same either way, so it doesn't affect this stylesheet.

The way this module works is interesting. It contains template rules that override all other rules in the base stylesheet. For example, changes marked as additions (
@diff=“add”
) are handled by this rule:


  

    

      

       chg

      

    

    

      

    

  


This matches every element with the attribute
diff=“chg”
, indicating that the content has changed. If the global parameter
$show.diff.markup
is set to 0, to disable change marking, the template calls

, which, like a call on
super()
in an object-oriented program, invokes the base template rule in the imported stylesheet (in this case
xmlspec.xsl)
. Otherwise, it invokes a named template
diff-markup.
, which we will now examine. The template reads:

Other books

The River King by Alice Hoffman
A Sea of Troubles by David Donachie
Love You to Death by Melissa Senate
A God and His Gifts by Ivy Compton-Burnett
A Thousand Kisses Deep by Wendy Rosnau
Bloodkin by Amelia Atwater-Rhodes
The Beloved One by Danelle Harmon

© 100 Vampire Novels China Edition 2015 - 2024    Contact for me [email protected]