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

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


  off

  

    

      

      

      

    

    

      

      

    

    

      

        

      

    

    

      

        

      

    

    

      

        

      

    

    

      

        

      

    

    

      

        

      


    

  


This is pretty pragmatic code, and it almost certainly doesn't handle all possible cases. In effect, it recognizes that the
diff
attribute can occur in three different contexts: contexts where a

element can be added to the HTML, contexts where a


element can be added to the HTML, and contexts where nothing can be done. In the first two cases, the

or

element is added, with a
class
attribute that will invoke a CSS rule to cause the text to be displayed with a background color.

But the magic is in the

instruction, which says that having added a


or

element, the stylesheet should go on to process the element exactly as it would have done if the
diffspec.xsl
stylesheet module had not been invoked. The effect of this stylesheet module is thus entirely additive.

As well as the

rule, there are similar rules for
[@diff=“add”]
and
[@diff=“del”]
.

There are a few other points to note about this stylesheet module.

Firstly, it contains the declaration

. This points up a nice little problem: How would one maintain a
diffspec.xsl
module that could be used as an overlay over a variety of different base stylesheets? To achieve this, the module could not import the underlying module, which means it could not use

to invoke the overridden template rules. An apparent solution would be to use a third module,
xmlspec-diff.xsl
, which imports both
xmlspec.xsl
and
diffspec.xsl
. Unfortunately, though, the rules for

don't allow this: this instruction will not consider all template rules of lower precedence, but only those in modules that have been directly imported. The new

instruction in XSLT 2.0 comes nicely to the rescue here.

Secondly, the stylesheet has a template rule, about 50 lines long, for

. This overrides the corresponding rule in the base stylesheet, and the only difference is that it outputs some text explaining the meaning of the change highlighting. Clearly duplicating so much code from the base stylesheet creates a problem in managing subsequent changes. There are a number of other ways to achieve the required effect. One way is to insert an

instruction to an empty template rule at the appropriate point in the base template; this can then be overridden in the overlay. If it is not possible to modify the base template, another solution is to write a template that invokes the base template by using

, capturing the results in a variable, and then perform a further transform on the contents of the variable. In this example, the XSLT 2.0 solution would look like this:


  

    

  

  

    

    

      


        

The presentation of this document has been augmented to identify

           changes from a previous version…


      


      

    

  


REC-xml.xsl

The third module in the stylesheet is called
REC-xml.xsl
. Compared with
xmlspec.xsl
, this module is rather poorly documented. The thinking is apparently that
xmlspec.xsl
should be a generic stylesheet that applies to all the W3C specifications (or at any rate, all those that are authored in XML), while
REC-xml.xsl
is a customization for the XML Recommendation in particular.

Looking through the contents of this stylesheet, most of it appears to be rather pragmatic. For example, it recognizes that an

element can have a
role
attribute with values such as
“2e”
,
“3e”
, and
“4e”
, and thus allows the published output to distinguish between authors of each edition of the specification. The
role
attribute is permitted on pretty well any element in the DTD, and has no defined values; a comment in the DTD makes it fairly clear that it is intended as a general-purpose extensibility mechanism to allow document editors to add information that can't otherwise be captured.

Other books

The Stonemason by Cormac McCarthy
Don't Call Me Hero by Eliza Lentzski
False God of Rome by Robert Fabbri
Angels' Blood by Nalini Singh
Los reyes de lo cool by Don Winslow
Finding Home by Ann Vaughn
Now Playing by Ron Koertge
Darkfall by Denise A. Agnew

© FullEnglishBooks 2015 - 2024    Contact for me [email protected]