Wednesday, July 18, 2007

Using Css :

------------------


A stylesheet is a document that contains formatting rules for one or more XML or HTML documents.


we can define our own template for the style of the font.



style.css :

-----------------

CATALOG

{

background-color :#00ff00 ; <!-- Sets the background color as green -->

}




test.xml :

==========


<?xml version = "1.0" ?>

<?xml:stylesheet type ="text/css" href ="D:style.css" ?>

<CATALOG> Sundar

</CATALOG


if we run the test.xml in internet explorer, then IE displays the text "Sundar" with background as Green.



XSL :

----------

CSS doesnot support the reorder,sort and display of elements based on a condition. To Help us perform such operations,

XML supports another style sheet language called Extensible Style Sheet(XSL).


XSL has two parts :


1. XSL Transformations (XSLT)

This XML based language allows us to transform an XML document into other formats such as HTML and XHTML.

2.XML Path ( XPath)

This language is used to access parts of an XML document such as elements and attributes.



XSL contains formatting objects (how the data is to be displayed)

XSLT contains instructions on how an XML document should be transformed in to an HTML or XHTML documents.

XSLT uses XPath expressions to extract specific data from an XML document.


XPath expressions contain mathematical, relational, equality and logical operators to specify the conditions for formatting the XML document.


XSLT Processor reads the XSLT instructions and transforms the XML document into HTML or XHTML document or into another XML document.


This transformed document then uses the XSL formatting objects to display the document in the desired format.



Comparing CSS and XSLT :


XSLT is a superset of the CSS functionality. we can use XSLT to display selective elements or attibutes, sort data on one or more elements,


and process the data based on a condition.


XSLT is an application of XML. XSLT follows XML syntax. XSLT is intended for complex formatting.



Difference between CSS and XSLT




S.No CSS XSLT



1 Simple To use and is suitable for simple documents complex to use


2 cannot reorder,add,delete or perform operations on elements can Reorder,add or delete elements, because it is aware of the structure of

XML document.


3. Doesnot offer access to non-elements such as Allows accessing and manipulating comments,PI values within

attributes, attribute values and PI an XML document


4. Uses less memory Uses more memory and processor power because we can reorder,add, delete

and manipulate the elements that require a tree representation of the document

in memory


5. Doesnot use XML syntax Written using XML and follows XML syntax.





XSLT Processor :


XSLT processor is packaged along with the Microsoft XML parser.

The XML parser can be used to parse an XSLT document, because XSLT is an application of XML. The MSXML parser parses the XSLT style sheet and creates


a tree structure based on the elements and attributes used in the XSLT document. this tree is referred as XSL tree.


The XSLT processor of the MSXML parser takes the transformation information contained in the XSLT stylesheet, applies it to the data

retrieved from the source document, and builds a tree structure referred to as the result tree. This tree is then rendered to various targets, such as web browsers,

pagers and cellphones.



Formatting Data using XSLT :


XSLT provides the following elements to select and format data :


1.stylesheet

2.value-of

3.for-each

4.sort

5.text



stylesheet element :

----------------------------

A Style sheet declaration is added in the XSLT file to instruct the browser that it is a style sheet file.This is required because

the XSLT stylesheet contains instructions to transform the XML document.



<xsl:stylesheet xmllns: xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0">


value-of element :

-------------------------

this element displays the value of the specified element or attribute.


<xsl:value-of select ="elementName/attributeName" />



For displaying the element value


Example : <FirstName>John </FirstName>

<xsl:value-of select ="FirstName"> - Display the value of the FirstName.


For displaying the attribute value we must prefix @ symbol.


<xsl:value-of select ="@Product">


The for-each element :

--------------------------------

This element is used to instruct the XSLT processor to process the information for each instance of the specified pattern.


<xsl:for-each select ="pattern">

{action to be performed}

</xsl:for-each>

sort element :

--------------------

This element is used to sort data based on the values assigned to elements and attributes.


text Element ;

----------------------


text Element allows us to generate constant text in output. It can be used to display labels.


Example :

<xsl:text> ProductName: </xsl:text>


Formatting Data using XSL formatting objects :


1.XSL -FO is an XML based language that allows us to format XML documents into pages, paragraphs and lists.

It is used to specify pagination, layout, and formatting information for XML documents.



structure of an XSL-FO Document :

<?xml version = "1.0" encoding = "ISO-8859-1" ?>

<fo:root xmlns:fs= "http://www.w3.org/1999/XSL/Format" >

</fo:root>

0 Comments:

Post a Comment

<< Home