Rahul
Rahul

Reputation: 11679

what is the need of xsl when compared with css?

Well i happened to run through some code snippets and couldnt understand the need for xsl when the same thing can be done using css. For example

<?xml-stylesheet type = "text/css" href = "6a.css" ?>
<ENG-COLLEGE>
   <XYZ>
     <USN>145456</USN>
     <NAME>ABC</NAME>
     <COLLEGE>TYUIT</COLLEGE>
     <BRANCH>ISE</BRANCH>
     <YEAR>2003</YEAR>
     <EMAIL>[email protected]</EMAIL>
   </XYZ>
<ENG-COLLEGE>

Equivalent CSS code for styling that

USN{font-family:'sans serif';color:orange;font-size:15pt;}
NAME{font-family:'arial';color:red;font-size:15pt;}
COLLEGE{font-family:'Times New Roman';color:lime;font-size:15pt;}
BRANCH{font-family:'Comic Sans MS';color:gray;font-size:15pt;}
YEAR{font-family:'Century Gothic';color:blue;font-size:15pt;}
EMAIL{font-family:'Georgia';color:green;font-size:15pt;}

Althought the same styling could be achieved using xsl , which involves more lines of code

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

 <xsl:template match = "ENG-COLLEGE">

   <html><head><title>Test XSL</title>
    </head><body bgcolor="lightgreen">
   <center><h2>INFORMATION </h2>
    <table border="1">

<tr><td>USN</td><td>NAME</td><td>COLLEGE</td><td>BRANCH</td><td>YEAR</td>    <td>EMAIL</td></tr>

     <xsl:for-each select ="VTU">
     <tr>
       <td> <xsl:value-of select = "USN" /></td>
    <td><xsl:value-of select = "NAME" /></td>
    <td><xsl:value-of select = "COLLEGE" /></td>
    <td> <xsl:value-of select = "BRANCH" /></td>
   <td><xsl:value-of select = "YEAR" /></td>
   <td><xsl:value-of select = "EMAIL" /></td>
      </tr>
      </xsl:for-each>

     </table>

      </center>
      </body></html>

     </xsl:template>
      </xsl:stylesheet>

well am i missing something here , i mean why would anyone style using xsl when css can make the job so easy.

Upvotes: 0

Views: 404

Answers (2)

LarsH
LarsH

Reputation: 28004

Well i happened to run through some code snippets and couldnt understand the need for xsl when the same thing can be done using css. For example

What's true for that CSS-oriented example is not true in general. If your input XML contained many <XYZ> elements:

<ENG-COLLEGE>
   <XYZ>
     <USN>145456</USN>
     <NAME>ABC</NAME>
     <COLLEGE>TYUIT</COLLEGE>
     <BRANCH>ISE</BRANCH>
     <YEAR>2003</YEAR>
     <EMAIL>[email protected]</EMAIL>
   </XYZ>
   <XYZ>
     <USN>145456</USN>
     <NAME>DEF</NAME>
     ...
   </XYZ>
   etc.
</ENG-COLLEGE>

and you need to produce a table of these records, sorted by the content of the NAME element, omitting those whose YEAR is prior to 2000, with the EMAIL address surrounded by a "mailto" link... How would you do that in CSS?

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799130

CSS applies style and positioning. XSLT transforms one XML document into another. They're not doing the same job at all.

Upvotes: 6

Related Questions