Format the obtained XML data using a stylesheet, which is perfectly OK if you use a single XML file, embed the SXL file inside the XML file, but don't do this now, get the XML data directly, and then call the XSL file to format the data.
This part of the demo program needs to use the AJAX client framework, as shown in the following example:
1.ceshi.jsp
<%@ page contenttype= "TEXT/HTML;CHARSET=GBK"%>
<script language= "JavaScript src=" js\ Request.js "></script>
<script language=" javascript "
function Showxml () {
var url =" Vehicles.xml ";
Get_request (URL, "text");
}
Function Pagechange (responsetext) {
var xml = new ActiveXObject ("Microsoft.XMLDOM");
Xml.async = false;
//load The text of XML data
Xml.loadxml (responsetext);
var xsl = new ActiveXObject ("Microsoft.XMLDOM");
Xsl.async = false;
//Load the XSL
xsl.load ("vehicles.xsl");
var div = document.getElementById ("show");
div.innerhtml = Xml.transformnode (XSL); The
/**//*
Load () function loads an XML file
Loadxml () function to load XML data in the form of a string
*/
}
</script>
< P
<input type= "Submit" name= "Submit" value= "submitted" onclick= "Showxml ()"/>
</p>
<div id= " Show "></div>
2.vehicles.xml
<?xml version="1.0" encoding="gb2312"?>
<!--?xml-stylesheet href='Vehicles.xsl' type='text/xsl'?-->
<vehicles>
<vehicle year="1002" make="Land Rover" model="Discovery">
<mileage>36500</mileage>
<color>black</color>
<price>$32999</price>
</vehicle>
</vehicles>
3.vehicles.xsl
<?xml version= "1.0"?>
<xsl:stylesheet xmlns:xsl= "Http://www.w3.org/TR/WD=xsl" >
<xsl:template match= "/" >
<title>uuu</title>
<body>
<table align= "center" border= "2" >
<tr>
<th>Year</th>
<th>Make</th>
<th>Model</th>
<th>Mileage</th>
<th>Color</th>
<th>Price</th>
</tr>
<xsl:for-each order-by= "+price" select= "Vehicles/vehicle" >
<tr>
<td><xsl:value-of select= "@year"/></td>
<td><xsl:value-of select= "@make"/></td>
<td><xsl:value-of select= "@model"/></td>
<td><xsl:value-of select= "Mileage"/></td>
<td><xsl:value-of select= "Color"/></td>
<td><xsl:value-of select= "Price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</xsl:template>
</xsl:stylesheet>
4. Notes
You need to be aware of the XML loading, the XSL file loading, and the Xml.transformnode (XSL) method.