0% found this document useful (0 votes)
110 views6 pages

Eg1.xml: An User Is Identified

The document contains examples of XML files (eg1.xml, temp.xml, customer.xml, students.xml) and XSL stylesheet files (list0.xsl - list4.xsl, test2.xsl, students.xsl, students1.xsl) that are used to transform and display the XML data. The XML files contain user, customer and student data, while the XSL files define templates to match elements and extract/display specific values when transforming the XML files.

Uploaded by

Deepa Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views6 pages

Eg1.xml: An User Is Identified

The document contains examples of XML files (eg1.xml, temp.xml, customer.xml, students.xml) and XSL stylesheet files (list0.xsl - list4.xsl, test2.xsl, students.xsl, students1.xsl) that are used to transform and display the XML data. The XML files contain user, customer and student data, while the XSL files define templates to match elements and extract/display specific values when transforming the XML files.

Uploaded by

Deepa Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

eg1.

xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="list0.xsl"?>
<UserList>
<User>
<Name>Sree Harini</Name>
<Account>Savings</Account>
</User>
<User>
<Name>Harini Sree</Name>
<Account>Current</Account>
</User>
</UserList>
list0.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:stylesheet>

list1.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="User">
An user is identified
</xsl:template>
</xsl:stylesheet>
list2.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="User">
<p> An user is identified </p>
</xsl:template>
</xsl:stylesheet>

list3.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="User">
<p>
<xsl:value-of select="Name"/>
</p>
</xsl:template>
</xsl:stylesheet>
temp.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="list0.xsl"?>
<UserList>
<test>
<t1>welcome</t1>
<t2>hello</t2>
</test>
<User>
<Name>Sree Harini</Name>
<Account>Savings</Account>
</User>
<User>
<Name>Harini Sree</Name>
<Account>Current</Account>
</User>
<test>
<t1>welcome</t1>
<t2>hello</t2>
</test>
</UserList>

list4.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="User">
<xsl:value-of select="Name"/>
</xsl:template>

<xsl:template match="UserList">
<xsl:apply-templates select="User" />
</xsl:template>
</xsl:stylesheet>

customer.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test2.xsl" ?>
<customers>
<customer>
<name>John Smith</name>
<address>123 Oak St.</address>
<state>WA</state>
<phone>(206) 123-4567</phone>
</customer>
<customer>
<name>Zack Zwyker</name>
<address>368 Elm St.</address>
<state>WA</state>
<phone>(206) 423-4537</phone>
</customer>
<customer>
<name>Albert Aikens</name>
<address>368 Elm St.</address>
<state>WA</state>
<phone>(206) 423-4537</phone>
</customer>
<customer>
<name>Albert Gandy</name>
<address>6984 4th St.</address>
<state>WA</state>
<phone>(206) 433-4547</phone>
</customer>
<customer>
<name>Peter Furst</name>
<address>456 Pine Av.</address>
<state>CA</state>
<phone>(209) 765-4321</phone>
</customer>
<customer>
<name>Dan Russell</name>

<address>9876 Main St.</address>


<state>PA</state>
<phone>(323) 321-7654</phone>
</customer>
</customers>
test2.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<HTML>
<BODY>
<TABLE border="1">
<xsl:for-each select="customers/customer">
<xsl:sort select="state" />
<TR>
<TD><xsl:value-of select="name" /></TD>
<TD><xsl:value-of select="address" /></TD>
<TD><xsl:value-of select="phone" /></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
Output

students.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="students.xsl"?>
<class>
<student rollno="393">
<firstname>Dinkar</firstname>
<lastname>Kad</lastname>
<nickname>Dinkar</nickname>
<marks>85</marks>
</student>
<student rollno="493">
<firstname>Vaneet</firstname>
<lastname>Gupta</lastname>
<nickname>Vinni</nickname>
<marks>95</marks>
</student>
<student rollno="593">
<firstname>Jasvir</firstname>
<lastname>Singh</lastname>
<nickname>Jazz</nickname>
<marks>91</marks>
</student>
</class>
students.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> <body>
<h2>Students with mark greater than 90 </h2>
<table border="1">
<xsl:for-each select="class/student">
<xsl:if test="marks > 90">
<tr>
<td> <xsl:value-of select="@rollno"/> </td>
<td> <xsl:value-of select="firstname"/> </td>
<td> <xsl:value-of select="marks"/> </td>
</tr>
</xsl:if>
</xsl:for-each>
</table> </body> </html>
</xsl:template>
</xsl:stylesheet>

students1.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> <body>
<h2>Students</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Roll No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nick Name</th>
<th>Marks</th>
<th>Grade</th>
</tr>
<xsl:for-each select="class/student">
<tr>
<td>
<xsl:value-of select="@rollno"/>
</td>
<td><xsl:value-of select="firstname"/></td>
<td><xsl:value-of select="lastname"/></td>
<td><xsl:value-of select="nickname"/></td>
<td><xsl:value-of select="marks"/></td>
<td>
<xsl:choose>
<xsl:when test="marks > 90">
High
</xsl:when>
<xsl:when test="marks > 85">
Medium
</xsl:when>
<xsl:otherwise>
Low
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</table>
</body> </html>
</xsl:template>
</xsl:stylesheet>

You might also like