XML Document Style

XML documents are used for human viewing too. However, when you access the XML document in a web browser, it will not display the content as HTML page do. Though both are markup languages.

XML Raw Data

XML do not have style information and show the row data which is little difficult to understand. The following figure is one such example.

Advertisements
Figure 1 – Raw XML data is shown in HTML browser

The figure above shows raw data about student and the browser indicate that there is no style information attached.

HTML Stylesheets

The HTML is also a markup language, but it has certain tags that help format the style information of the document. Let say you want to bold title for you document. Then there are header styles from <h1> to <h6>. There are other font styling tags such as italic (<i>), bold (<b>), etc.

Other document style information is provided by Cascading Style Sheet also known as CSS. The style information is kelp separate from the document. It is because changing the style for a particular tag is difficult unless you are ready to rewrite the tags all over again.

<?xml version="1.0"?> 
<computer>
  <brand>Compaq</brand>
  <model>Compaq Presario</model>
  <ram>1 <i>GB, DRAM</i> </ram>
  <disk>10 GB</disk>
  <monitor>22 in</monitor>
  <price><i>Rs 35000</i></price>
</computer>

In the above example, what if we want to change the style for <ram> and <price>. I have to rewrite the whole thing, that exactly is the problem. For smaller documents, I can manage, not with a document with 10000 lines.

Advertisements

XML Stylesheet

The XML also follows the standard of HTML and has its own stylesheet to keep the style information separate, it is called XSLT (extensible Language Stylesheet Transformation). Note the word “transformation”. The XSLT is more powerful than the CSS because not only, it provides with style information, it can add or remove elements from the final output. At this point, I don’t want to discuss the full abilities of XSLT.

The XSLT also use XPath to attach the stylesheet information to the XML document. One excellent feature of XSLT is the ability to transform XML document to HTML.

Summary

In this lesson, you learned that the style information is not supported by XML tags. It is kept separate like HTML document which uses CSS. The style information is managed by XSLT for XML documents, which has more abilities than CSS, as it can transform the XML document itself.

Advertisements

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Exit mobile version