0% found this document useful (0 votes)
46 views3 pages

Exp 7th WT-1

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

Exp 7th WT-1

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

EXP NO: 7

Programs using XML – Schema – XSLT/XSL

ALGORITHM:
1. Start the program.
2. Create XML Data File:
3. Define an XML file named library.xml with a root element <library>.
4. Link library.xml to an XSLT file (Book.xsl) using an XML stylesheet directive:
5. Define XSLT File for Transformation
6. Iterate through XML Data
7. Deploy XML and XSLT Files
8. The browser will apply the XSLT transformation, rendering the XML data as an HTML table.
9. Verify that the browser displays the book information correctly in a table format.
10. Stop the program.

File Structure
/LibraryProject

|---library.xml # The XML file with book data

|---Book.xsl # The XSLT file for transforming XML into HTML

|---- Books.xsd # The XML Schema file (for validation if needed)

PROGRAM:

library.xml
<?xml version="1.0" encoding="UTF-8"?>

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

<library>

<book>

<title>XML Developer's Guide</title>

<author>John Doe</author>

<price>44.95</price>

<publish_year>2000</publish_year>

</book>

<book>

<title>Learning XML</title>

<author>Jane Smith</author>

<price>39.95</price>
<publish_year>2003</publish_year>

</book>

</library>

Book.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>

<head>

<title>Library Books</title>

</head>

<body>

<h2>Library Books</h2>

<table border="1">

<tr bgcolor="#9acd32">

<th>Title</th>

<th>Author</th>

<th>Price</th>

<th>Publish Year</th>

</tr>

<xsl:for-each select="library/book">

<tr>

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

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

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

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

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>
Books.xsd
<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="library">

<xs:complexType>

<xs:sequence>

<xs:element name="book" maxOccurs="unbounded">

<xs:complexType>

<xs:sequence>

<xs:element name="title" type="xs:string" />

<xs:element name="author" type="xs:string" />

<xs:element name="price" type="xs:float" />

<xs:element name="publish_year" type="xs:integer" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

You might also like