0% found this document useful (0 votes)
44 views4 pages

Answer 2

The document contains code for an HTML page that uses XML, XSLT, and JavaScript to dynamically display book data from an XML file. The HTML page includes a button that runs a JavaScript function to fetch the XML and XSLT files, transform the XML using XSLT, and display the results inside a div element on the page.

Uploaded by

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

Answer 2

The document contains code for an HTML page that uses XML, XSLT, and JavaScript to dynamically display book data from an XML file. The HTML page includes a button that runs a JavaScript function to fetch the XML and XSLT files, transform the XML using XSLT, and display the results inside a div element on the page.

Uploaded by

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

html

<!DOCTYPE html>

<html>

<head>

<title>Two Frames Example</title>

</head>

<frameset rows="50%,50%">

<frame src="column1.html" name="frame1">

<frameset cols="50%,50%">

<frame src="column2.html" name="frame2">

<frame src="column3.html" name="frame3">

</frameset>

</frameset>

</html>

xml(books.xml)
<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book>

<title>Book 1</title>

<author>Author 1</author>

<price>25.00</price>

</book>

<book>

<title>Book 2</title>

<author>Author 2</author>

<price>20.00</price>

</book>

<!-- Add more book entries as needed -->

</bookstore>
xslt (books.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>Bookstore</title>

</head>

<body>

<h1>Bookstore</h1>

<table border="1">

<tr>

<th>Title</th>

<th>Author</th>

<th>Price</th>

</tr>

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

<tr>

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

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

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

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>
HTML Page (bookstore.html)

<!DOCTYPE html>

<html>

<head>

<title>Bookstore</title>

<script>

function transformXML() {

var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

var xml = this.responseXML;

var xsl = new XMLHttpRequest();

xsl.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

var xsltProcessor = new XSLTProcessor();

xsltProcessor.importStylesheet(this.responseXML);

var resultDocument = xsltProcessor.transformToDocument(xml);

document.getElementById("output").innerHTML = new
XMLSerializer().serializeToString(resultDocument);

};

xsl.open("GET", "books.xsl", true);

xsl.send();

};

xhttp.open("GET", "books.xml", true);

xhttp.send();

</script>

</head>

<body>
<h1>Bookstore</h1>

<button onclick="transformXML()">Show Books</button>

<div id="output"></div>

</body>

</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy