11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

one. Fortunately, although not apparent from the DTD rules in this brief example, XML<br />

significantly reduces the complexity of full SGML. However, regardless of how easy or hard it is<br />

to write a language definition, readers might wonder how to present an XML document once it<br />

is written.<br />

Displaying XML<br />

Notice that inherently, XML documents have no predefined presentation; thus we must define<br />

one. While this may seem like a hassle, it actually is a blessing as it forces the separation of<br />

content structure from presentation. Already, many Web developers have embraced the idea of<br />

storing Web content in XML format and then transforming it into an appropriate output format<br />

such as HTML or XHTML and CSS using eXtensible Style Sheet Transformations (XSLT),<br />

which is part of the eXtensible Style Sheets (XSL) specification or some form of server-side<br />

programming. It is also possible to render XML natively in most browsers by binding CSS<br />

directly to user-defined elements.<br />

Note In many cases, developers simply refer to XSL rather than XSLT when discussing the<br />

features provided by the latter.<br />

Using XSLT to Transform XML to HTML<br />

With XSLT, you can easily transform and then format an XML document. Various elements and<br />

attributes can be matched using XSL, and other markup languages such as HTML or XHTML,<br />

and then can be output. Let‘s demonstrate this idea using client-side processed XSL found in<br />

most modern browsers. Consider the following simple well-formed XML document called<br />

demo.xml:<br />

<br />

<br />

<br />

Look <br />

formatting <br />

XML <br />

as HTML<br />

<br />

Notice that the second line applies an XSL file called test.xsl to the document. That file will<br />

create a simple HTML document and convert each occurrence of the tag to an<br />

tag. <strong>The</strong> XSL template called test.xsl is shown here:<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!