[thelist] XML/XSLT & ASP question

David.Cantrell at Gunter.AF.mil David.Cantrell at Gunter.AF.mil
Wed Nov 13 10:23:00 CST 2002


>I know how to get the xml out of an external file, but I want to pull
>the xml from the asp file itself, out of the response buffer, because I
>want to make it so that regular people (not programming people) can edit
>the files. It would be very hard for them to do something like this:
>
><%
>xmlStr = xmlStr & "<content>"&vbcrlf
>xmlStr = xmlStr & "my content goes here"&vbcrlf
>xmlStr = xmlStr & "</content>"&vbcrlf
>%>
><!--#include file="transform.asp"-->
>
>
>... than for them to do something like this:
>
><content>
>my content goes here
></content>
><!--#include file="transform.asp"-->

OK, I see what you are trying to do. There's a better way however.

First, what is the intended browser audience? Are you using an XSL
stylesheet for the transform? If so, just specify the desired stylesheet
inline with the XML file like this:

	<?xml-stylesheet type="text/xsl" href="transform.xsl"?>
	<content>
		my content goes here
	</content>

Then when IE gets the file it will transform it client-side automatically
using the specified stylesheet. The MSXML SDK documentation has a section on
this, entitled "Displaying XML Files in a Browser". This may also work on
Mozilla, not 100% sure though.

If you want it to be available on more browsers though, try creating a
transform.asp script which takes the path to the XML file to be transformed
and returns the result. Off the top of my head this should work:

	<%
	Option Explicit

	Const XSL_PATH = "transform.xsl"

	dim sPath : sPath = Request.Querystring( "src" )

	dim oXml : Set oXml = Server.CreateObject( "Msxml2.DomDocument.4.0"
)
	oXml.Load Server.MapPath( sPath )

	dim oXsl : Set oXsl = Server.CreateObject( "Msxml2.DomDocument.4.0"
)
	oXsl.Load Server.MapPath( XSL_PATH )

	response.write oXml.TransformNode( oXsl )

	Set oXsl = Nothing
	Set oXml = Nothing
	%>

Then the script can be called from the browser like:

	transform.asp?src=myFile.xml

You could modify the transform script to accept a second parameter as the
path to an XSL file, so you wouldn't have to hardcode it into the file.

Just some thoughts...

HTH,
-dave



More information about the thelist mailing list