The Root Rule
The root element defines the HTML elements that control the overall
structure of the document. The elements that can be defined using
<root> are the HTML, HEAD, and BODY elements, and any associated
elements they may contain.
To demonstrate the root rule, I added the HTML, HEAD, and BODY elements
to the document, and included the title for the document as part of the
head. The XSL for this rule is defined in the following block:
<rule>
<root/>
<HTML>
<HEAD>
<TITLE>XML
</TITLE>
</HEAD>
<BODY>
<children/>
</BODY>
</HTML>
</rule>
Once processed, the generated HTML from this XSL defines the overall
structure of the document, as you can see with the
generated
output. Check out the source by using the "View Source" option defined
for the browser. Notice that the document now has a title, a header,
and a body, and is delimited by opening and closing HTML tags.
Not only can the HEAD, BODY, and HTML elements be defined within the
root, but scripting blocks can also be included within a root element.
For example, to add a scripting block to the root requires that a CDATA
block be used to enclose the script. CDATA is an XML language
specification to define content that is not to be processed, but to be
passed through to the generated output as is. The following code
demonstrates adding scripting to an XSL file:
<rule>
<root/>
<HTML>
<HEAD>
<TITLE>XML
</TITLE>
<SCRIPT language="Javascript"><![CDATA[
function test() {
alert("hello");
}
]]></SCRIPT>
</HEAD>
<BODY onload="test()">
<children/>
</BODY>
</HTML>
</rule>
This generated example
will display a message with "hello" when the page loads.
Our discussion to this point has focused on matching patterns.
With XSL, the absence of a pattern is just as telling as the
pattern itself, as this implies a wildcard, discussed next.
Adding Parental Patterns to the XSL Rule
Add a little style to your XML document with XSL - a Working Example
Wildcards
|