Applying XSLT with the DOM in ASP


ASP code:

<%
xmlFile="paras.xml"
set theBrowser=Server.CreateObject("MSWC.BrowserType")
if ((theBrowser.browser="IE") and (theBrowser.majorver>4)) then
Response.Redirect(xmlFile)
else
sourceFile=Server.MapPath(xmlFile)
set sourceDOM=Server.CreateObject("Microsoft.XMLDOM")
sourceDOM.async=false
sourceDOM.load(sourceFile)
set styleDOM=Server.CreateObject("Microsoft.XMLDOM")
styleFile=Server.MapPath("paras2.xsl")
styleDOM.async=false
styleDOM.load(styleFile)
Response.Write(sourceDOM.transformNode(styleDOM))
end if
%>

XML Document

<?xml version="1.0"?>
<?xml-stylesheet href="paras2.xsl" type="text/xsl"?>
<document>
<paragraph>This is my <num>first</num> paragraph.</paragraph>
<paragraph>This is my <num>second</num> paragraph.</paragraph>
<paragraph>This is my <num>third</num> paragraph.</paragraph>
</document>

XSL Stylesheet (IE-only)

<?xml version="1.0"?>
<xsl:stylesheet 
	xmlns:xsl="http://www.w3.org/TR/WD-xsl"
	xmlns="http://www.w3.org/TR/REC-html40">

<xsl:template match="textnode()"><xsl:value-of/></xsl:template>
<xsl:template match="/"><xsl:apply-templates/></xsl:template>
<xsl:template match="document">
<html>
<body>
		<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="paragraph">
	<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="num">
	<b><xsl:value-of /></b>
</xsl:template>
</xsl:stylesheet>

<Origin Page   TOC

Copyright 2000 Simon St.Laurent