vbscript and xsl

Discussion in 'ASP General' started by kieran, Aug 19, 2004.

  1. kieran

    kieran Guest

    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>
     
    kieran, Aug 19, 2004
    #1
    1. Advertising

  2. kieran

    Ray at Guest

    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

    "kieran" <> wrote in message
    news:...
    > 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>
     
    Ray at, Aug 19, 2004
    #2
    1. Advertising

  3. "kieran" <> wrote in message
    news:...
    > 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
     
    Chris Hohmann, Aug 19, 2004
    #3
  4. kieran

    kieran Guest

    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

    %>
     
    kieran, Aug 20, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karsten Weinert
    Replies:
    3
    Views:
    1,014
    Karsten Weinert
    Jul 5, 2004
  2. kieran

    vbscript and xsl

    kieran, Aug 19, 2004, in forum: XML
    Replies:
    0
    Views:
    762
    kieran
    Aug 19, 2004
  3. Vijay singh
    Replies:
    1
    Views:
    436
    Martin Honnen
    Nov 4, 2004
  4. David Carlisle

    xsl:import and xsl:apply_import

    David Carlisle, Dec 16, 2004, in forum: XML
    Replies:
    5
    Views:
    495
    Shiju Rajan
    Dec 16, 2004
  5. Replies:
    1
    Views:
    3,613
    A. Bolmarcich
    May 27, 2005
Loading...

Share This Page