HTML and CSS Reference
In-Depth Information
The application of XSLT elements is straightforward and follows general XML authoring principles. Listing 5-80
shows an example.
Listing 5-80.
XSLT Elements and Attributes Correspond to XML Guidelines
<xsl:param name="page-header-margin">20px</xsl:param>
Standard Attributes
Several standard attributes are associated with XSLT elements, including
version
,
exclude-result-prefixes
,
extension-element-prefixes
,
xpath-default-namespace
,
default-collation
, and
use-when
. To distinguish
them from attributes defined by authors, they should be written with the namespace notation as
xsl:version
,
xsl:exclude-result-prefixes
,
xsl:extension-element-prefixes
,
xsl:xpath-default-namespace
,
xsl:default-
collation
, and
xsl:use-when
.
Combining CSS and XSL
XSL can also be used as a bridge between complex XML-based documents and the CSS formatting model. Since
CSS has no XML syntax, CSS properties become XML attributes in the XSL syntax. The main CSS object is
chunk
.
Additional objects might also be required. Usually they are other
chunk
objects with functionality such as
anchor
,
or further objects such as
switch
. For example, the CSS ruleset in Listing 5-81 can be written in XSL syntax, as
shown in Listing 5-82.
Listing 5-81.
CSS Ruleset Example to Be Converted into XSL
{
font-size: 1.2em;
text-indent: 1em;
}
Listing 5-82.
The XSL Equivalent of Listing 5-81
<css:chunk
font-size="1.2em"
text-indent="1em">
CSS Preprocessing
Although CSS is a powerful language, it has limitations compared to traditional programming languages and
especially object-oriented programming languages. For example, CSS does not support
mixins
such as classes
that contain a combination of methods from other classes. Another desirable CSS feature would be selector
inheritance, which is not supported by CSS. CSS has a set of selectors and pseudo-selectors that group rules
that apply to them.
CSS preprocessors
extend CSS by providing additional mechanisms available in traditional
programming languages, particularly object-oriented languages, but that are not available in CSS. Such
extensions are very useful in the development of large, complex websites and web applications,
9
providing
concise style sheets that are faster to write, and easier to maintain or update. One of the principles in CSS
preprocessing is
DRY
(Don't Repeat Yourself (as opposed to
WET
, Write Everything Twice). The most popular
CSS preprocessors are Sass, LESS, and Stylus.
9
Since CSS is abstracted, there is an additional step to updates and changes, which is not always worthwhile in small web projects.
Search WWH ::
Custom Search