XPath i Microsoft.XMLDOM
Jeg har følgende kode, hvor jeg et eller andet sted skal have indskudt en dynamisk genereret XPath, så jeg bl.a. kan lave datostyring og søgning. Jeg kan bare ikke gennemskue, hvor:JScript ASP:
//Load XML
var xml = Server.CreateObject("Microsoft.XMLDOM");
xml.async = false;
xml.load(Server.MapPath("xmltest.xml"));
//Load XSL
var xsl = Server.CreateObject("Microsoft.XMLDOM");
xsl.async = false;
xsl.load(Server.MapPath("xmltest.xsl"));
//Transform file
Response.Write(xml.transformNode(xsl));
xsl = null;
xml = null;
XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog>
XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:sort order="ascending" select="artist" />
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>