XSLT..

Monday 29 October 2012

Assalamualaikum wbrt everyone..



       
      For this coming entry I would like to share how to use XSLT to transform XML documents into other formats like HTML.. Did you have  heard XSLT before.? What is XSLT.? XSLT stands for XSL Transformations, and XSL stands for Extensible Stylesheet Language.. It is a stylesheet for XML documents..  




   1. First of all before you can write XSLT you need XML documents.. 
       XML  Example

         <?xml version='1.0' encoding='utf-8'?>
         <company>
                <employee>
                       <name>shaheer</name>
                       <position>CEO</position>
                </employee>
                <employee>
                       <name>yati</name>
                       <position>chief XML Evangelist</position>
                </employee>
         </company>

    2. Lets begin write XSLT
        - XSLT need XML declaration 
       
Description
Syntax
xml declaration
<?xml version='1.0' encoding='utf-8' ?>
xsl stylesheet declaration
 <xsl:stylesheet version='1.0'   
   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
xsl template declaration
<xsl:template match='/'>

</xsl:template>

 *write html inside xsl:template
      eg: <xsl:template match='/'>

            <html>

                        <body>

                                    <h1>Example</h1>

                        </body>

            </html>

           </xsl:template>
xsl method
 - for-each method, it like looping in java

 - xsl:value-of to get value 


     <xsl:for-each select="catalog/product">

            <td><xsl:value-of select="name"/></td>

     </xsl:for-each>
sorting
<xsl:sort select="name"/>
if we want to write style
- this like css

   <xsl:template name='style'>

            <style>

                        h1{COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}

                        tr{background-color: beige;}

                        td{COLOR: blue; FONT-FAMILY: Arial}

            </style>

   </xsl:template>
calling template
<xsl:call-template name='style'>

0 comments:

Post a Comment