Mega Code Archive

 
Categories / XML Tutorial / XSLT StyleSheet
 

Creating and Applying Template Rules

File: Data.xml   <?xml version="1.0"?> <employees>   <animal>     <name language="English">T1</name>     <name language="Latin">T2</name>     <projects>       <project>project1</project>     </projects>   </animal> </employees> File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="1.0">   <xsl:template match="/">     <html>       <head>         <title>this is the title</title>       </head>       <body bgcolor="white">         <xsl:apply-templates select="employees/animal" />       </body>     </html>   </xsl:template>   <xsl:template match="animal">     <p align="center">       <br />       <font size="+3">         <xsl:apply-templates select="name" />       </font>     </p>     <paragraph>       <xsl:value-of select="name[@language='English']" />       <a href="http://www.rntsoft.com">pages</a>     </p>     <hr />   </xsl:template>   <xsl:template match="name[@language='English']">     <nobr>       <b>         <xsl:value-of select="." />         :       </b>     </nobr>   </xsl:template>   <xsl:template match="name[@language='Latin']">     <nobr>       <i>         <xsl:value-of select="." />       </i>     </nobr>   </xsl:template> </xsl:stylesheet> Output: <html>    <head>       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">       <title>this is the title</title>    </head>    <body bgcolor="white">       <p align="center"><br><font size="+3">             <nobr><b>T1                           :                         </b></nobr>             <nobr><i>T2</i></nobr></font></p>       <paragraph>T1<a href="http://www.rntsoft.com">pages</a></p>       <hr>    </body> </html>