An unexpected benefit of having CSS inside XSLT templates is that
you can copy snippets of XSLT from one project to another, perhaps
to implement Web-page controls or other common functionality, and
the style is carried with them too. You could also do this if you
had the CSS before the individual XSLT
templates instead of inside them, but in that case you would have
the possibility of missing the styles for the first template, and
either the template would be separated from any xd:doc
elements preceding it, or the CSS would be before the
xd:doc
elements and hence separated too far from
the body of the template to reap the benefits of CSS Within.
The CSS Within approach relies on the CSS cascade mechanism: it is
because of this that is not necessary to specify full styles for
each generated element. This also means that a generated element
that can appear in multiple contexts may need multiple
css:rule
elements for the different contexts. As an
alternative, the base styles can be placed in the template
generating the ancestor element, and this relationship can be made
specific with a ref=
attribute on the individual
css:rule
elements to show the dependency. This
makes no difference to the generated CSS, but helps the human
maintainer of the stylesheet understand what has been done and keep
it up to date. The XSLT implementation does currently check the
ref
attributes.