Wednesday, March 11, 2009

XML & XSL EXAMPLE

<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="Input.xsl"?>

<project>
<class>
<type>private</type>
<Name>AddTwasdsoNumbers</Name>
</class>
<variable>
<var>
<type> int </type>
<Name>x</Name>
</var>
<var>
<type> int </type>
<Name>y</Name>
</var>

</variable>
<funtionmodule>
<var>
<Name>addtwonumber</Name>
<arg>
<type> int </type>
<Name>x</Name>
</arg>
<arg>
<type> int </type>
<Name>y</Name>
</arg>
<returntype> int </returntype>
</var>
</funtionmodule>

</project>

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

<xsl:template match="/">
<html>
<body>
<xsl:call-template name="project_class"/>
</body>
</html>
</xsl:template>

<xsl:template name="project_class">

<xsl:value-of select="project/class/type" disable-output-escaping="no"/>
<font color="red">class <xsl:value-of select="project/class/Name" disable-output-escaping="no"/> {
<br/></font> <div/>
<xsl:call-template name="project_Variable"/>
<br/>
<xsl:call-template name="project_Methods"/>
<br/>
}
</xsl:template>


<xsl:template name="project_Variable">

<xsl:for-each select="project/variable/var">

<xsl:value-of select="type" disable-output-escaping="no"/>

<xsl:value-of select="Name"/>
<br/>

</xsl:for-each>



</xsl:template>

<xsl:template name="project_Methods">
<xsl:for-each select="project/funtionmodule/var">
public <xsl:value-of select="returntype" disable-output-escaping="no"/> <xsl:value-of select="Name"/>() thrwos Exception{
<br/>
Rajnikanth

}
</xsl:for-each>


</xsl:template>


</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
-->





Another Example :

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="emp.xsl"?>

<database name="scott">
<table-name name="Employee">
<fields>
<column-name>empid</column-name>
<column-type>number</column-type>
<column-size>5</column-size>
</fields>
<fields>
<column-name>empname</column-name>
<column-type>varchar</column-type>
<column-size>5</column-size>
</fields>
</table-name>
<table-name name="Student">
<fields>
<column-name>studentid</column-name>
<column-type>number</column-type>
<column-size>5</column-size>
</fields>
<fields>
<column-name>studentname</column-name>
<column-type>varchar</column-type>
<column-size>5</column-size>
</fields>
</table-name>
</database>


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

<xsl:output method="html"/>

<xsl:template match="/">


<html>
<body>



<xsl:for-each select="database/table-name">
<table>
<tr>
<td><h4>Table Name:</h4></td><td><xsl:value-of select="@name"/></td>
</tr>
</table>
<table>
<tr width="250">
<th width="100">Name</th>
<th width="100">Type</th>
<th width="50">Size</th>
</tr>
<xsl:for-each select="fields">
<tr>
<td>
<xsl:value-of select="column-name"/>
</td>
<td>
<xsl:value-of select="column-type"/>
</td>
<td>
<xsl:value-of select="column-size"/>
</td>
</tr>
</xsl:for-each>
</table>
<br/>
<br/>
<br/>
</xsl:for-each>

========================
form submition
========================

<xsl:for-each select="database/table-name">
Table:<xsl:value-of select="@name"/>
<table>


<xsl:for-each select="fields">
<tr>

DB EMP NAME :<xsl:value-of select="column-name"/> :
USEREMPNAME :

<input type="text">
<xsl:attribute name="value"> <xsl:value-of select="column-name"/>
</xsl:attribute>
</input>
</tr>

</xsl:for-each>
</table>
</xsl:for-each>

</body>
</html>
</xsl:template>

</xsl:stylesheet>

No comments: