vbscript and xsl

K

kieran

Hi,

I have a vbscript function and an xsl file and when the vbscript
function is ran it creats the xml value that the xsl file then
transforms. It was done by Sharepoint so I figure there must be a way
for writing this so it works in one asp file. Some way of running the
function then putting the xsl file to transform it and outputting the
results.

I tried putting the xsl into an xsl editor, and then the function into
an xml editor enclosed in the
<SCRIPT language="VBSCRIPT"><![CDATA[
tags but no joy.

Any advice greatly appreciated.

--------------------------------------------------------------
Function GetContent(nod)
On Error Resume Next
'code removed for simplicity'
response.write "<News>" & ..... & "</News>"
End Function

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" omit-xml-declaration="no" indent="yes"
encoding="utf-8" />
<xsl:template match="/">
<TABLE>
<xsl:for-each select="Name">
<TR>
<TD valign="top" align="left">
<b><a
href='http://link/'><xsl:value-of select="."/></a></b>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
 
R

Ray at

I'm really not sure how this is ASP related. I'd try to put this post in a
more appropriate forum. And when you do, you may want to be a little more
descriptive than "no joy." What does that mean? Are you getting an error?
If so, what? And when doing what? What results do you expect from the
action you're taking? What results are you getting instead? Stuff like
that.

Ray at work
 
C

Chris Hohmann

kieran said:
Hi,

I have a vbscript function and an xsl file and when the vbscript
function is ran it creats the xml value that the xsl file then
transforms. It was done by Sharepoint so I figure there must be a way
for writing this so it works in one asp file. Some way of running the
function then putting the xsl file to transform it and outputting the
results.

I tried putting the xsl into an xsl editor, and then the function into
an xml editor enclosed in the
<SCRIPT language="VBSCRIPT"><![CDATA[
tags but no joy.

Any advice greatly appreciated.

--------------------------------------------------------------
Function GetContent(nod)
On Error Resume Next
'code removed for simplicity'
response.write "<News>" & ..... & "</News>"
End Function

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" omit-xml-declaration="no" indent="yes"
encoding="utf-8" />
<xsl:template match="/">
<TABLE>
<xsl:for-each select="Name">
<TR>
<TD valign="top" align="left">
<b><a
href='http://link/'><xsl:value-of select="."/></a></b>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>

Use the DOMDocument.loadXML method instead of the DOMDocument.load method to
load the XSL document from a string. I don't envy the task, you're going to
have to escape all the quotes contained in the XSL document. Here's a link
to the documentation for loadXML:

http://www.msdn.microsoft.com/library/en-us/xmlsdk/html/xmmthloadXML.asp
 
K

kieran

Cheers for that Chris.

You pointed me in the right direction and i got it working.

Heres the code for others -

<%

'Removes the SERVER NAME that is returned with the USERNAME
strNTUser = Trim(Request.ServerVariables("LOGON_USER"))
iPos = Len(strNTUser) - InStr(1, strNTUser, "\", 1)
strNTUser = Right(strNTUser, iPos)
strSQLUser = Replace(strNTUser,"_"," ")
strSQLUser=UCase(strSQLUser)

Dim sXML
Dim oDoc
sXML = "<?xml version=""1.0""?><name>" & strSQLUser & "</name>"


'Call the function - server.mappath means the file is in the root.
'loadXMLFile server.MapPath("test.xml"),server.MapPath("test.xsl")

loadXMLFile SXML,server.MapPath("test.xsl")


Function loadXMLFile(strXMLFile, strXSLFile)

'Declare local variables
Dim objXML
Dim objXSL


'Instantiate the XMLDOM Object that will hold the XML file.
set objXML = Server.CreateObject("Microsoft.XMLDOM")

'Turn off asyncronous file loading.
objXML.async = false

'Load the XML file.
objXML.loadXML(strXMLFile)


'Instantiate the XMLDOM Object that will hold the XSL file.
set objXSL = Server.CreateObject("Microsoft.XMLDOM")

'Turn off asyncronous file loading.
objXSL.async = false

'Load the XSL file.
objXSL.load(strXSLFile)


'Use the "transformNode" method of the XMLDOM to apply the
'XSL stylesheet to the XML document. Then the output is
'written to the client.
Response.Write(objXML.transformNode(objXSL))
End Function

%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top