---------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=euc-kr" />
<title>최신 영화 소식</title>
<script type="text/javascript" src="httpRequest.js"></script>
<script type="text/javascript" src="bookList.js"></script>
</head>
<body>
<div id="bookList"></div>
</body>
</html>
----------------
<?xml version="1.0" encoding="euc-kr" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes" encoding="euc-kr" />
<xsl:template match="books">
<ul>
<xsl:for-each select="book">
<li>
<strong><xsl:value-of select="title"/></strong>
(<em><xsl:value-of select="author" /></em>)
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
-------------------------
<%@ page contentType="text/xml; charset=utf-8" %>
<%@ page import="java.util.List" %>
<books>
<book>
<title>프로젝트 생존 전략</title>
<author>스티브 맥코넬</author>
</book>
<book>
<title>웹 표준 가이드</title>
<author>소프트웨어 진흥원</author>
</book>
<book>
<title>넛지</title>
<author>스티브 맥코넬</author>
</book>
</books>
--------------------------
window.onload = function(){
loadBooks();
}
function loadBooks(){
sendRequest("books.jsp",null,loadedBooksXML,"GET");
}
var xmlDoc = null;
var xslDoc = null;
function loadedBooksXML() {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
xmlDoc = httpRequest.responseXML;
sendRequest("books.xsl",null,loadedBooksXSL,"GET");
}
}
}
function loadedBooksXSL() {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
xslDoc = httpRequest.responseXML;
doXSLT();
}
}
}
function doXSLT(){
if(xmlDoc == null || xslDoc == null) return;
var bookList = document.getElementById("bookList");
if(window.ActiveXObject){ // IE방식의 xml문서를 xsl 변환
bookList.innerHTML = xmlDoc.transformNode(xslDoc);
}else{ // W3C 지원 브라우저의 xml문서를 xsl변환
var xsltProc = new XSLTProcessor();
xsltProc.importStylesheet(xslDoc);
var fragment = xsltProc.transformToFragment(xmlDoc,document);
bookList.appendChild(fragment);
}
}