Solved

ASP - SelectNodes - Error on Transform

Posted on 2011-02-21
8
876 Views
Last Modified: 2012-05-11
I am attempting to do a transform through ASP on some XML, then use an Xsl file to output the data.

I have to do selectNodes, so that I can dynamically change the "source" that I am searching on.
otherwise I would do it inside the XSL.

First code snippet is xmlretrieve.asp
step one, I retrieve a token from the api from appshore.net
I then insert that token into a url string, to retrieve the actual data I want to manipulate.
I then load it as an xmldom, and view the data without parsing it.  This works fine, and will output as expected. ' I did this for testing purposes
however when I then do a selectnodes on it.
and then attempt the transform, I get the following error.
Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'transformNode'
/xmlretrieve.asp, line 106


any thoughts?

 
<%
Response.Expires = -1
Dim Token
token= "https://hawkeyemgmt.appshore.net/xml.php?&op=base.auth.login&user_name=Unassigned&user_password=guest1234" 

Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xmlHttp.Open "GET", token, false
xmlHttp.Send()
RSSXML = xmlHttp.ResponseText

Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
xmlDOM.async = False
xmlDOM.validateOnParse = False
xmlDom.resolveExternals = False

If not xmlDOM.LoadXml(RSSXML) Then
ErrorMessage = "Can not load XML:" & vbCRLF & xmlDOM.parseError.reason & vbCRLF & ErrorMessage
End If

Set TokenGet = xmlDOM.getElementsByTagName("sid")
TokenGetCount = TokenGet.Length-1

For i = 0 To TokenGetCount
Set TokenGet = TokenGet.Item(i)
next


for each child in TokenGet.childNodes

TokenAuth = child.text
next


dim urlrequest
dim status2
dim strEMail
Dim objXML
Dim objNode
Dim objXSL

urlrequest= "https://hawkeyemgmt.appshore.net/xml.php?&sid=" & TokenAuth & "&op=leads.retrieve"
xmlhttp.Open "GET", urlrequest, false
xmlHttp.Send()
If xmlHttp.Status = 200 Then
    Set oResponseXML = xmlHttp.ResponseXML 'Save XML to an object
	
    bXMLLoadError = False
	Else
	 Response.Write("status="&xmlhttp.status & "<br>")
	Response.Write("<font color=""red"">Page Error: unknown Could not load XML from remote server</font><br>") 
	 
	 bXMLLoadError = True
End If


Set xmlHttp = Nothing ' clear HTTP object

%>

<%
'Initialise variables
' Attempting to actually retrieve the leads at this point.
Dim oXMLHTTP
Dim oResponseXML
Dim bXMLLoadError
Dim whoIwant

%>
<%

If Not bXMLLoadError Then

    'Load the XML from the oResponseXML object
    set oXML = Server.CreateObject("Microsoft.XMLDOM")
    oXML.Async = false
    oXML.Load(oResponseXML)

Set objNode = oXML.SelectNodes("API/leads/leads_item[source_id='Other']") ' at least four records contain Other

    'Load the XSL from disk   
  
   set oXSL = Server.CreateObject("Microsoft.XMLDOM")
   	
   oXSL.Async = False
  
   oXSL.Load(Server.MapPath("leads_retrieve.xsl"))
  ' This works as long as the other transform is commented out.
  Response.Write(oXML.transformNode(oXSL)) 'Transform the XML using the XSL stylesheet 

set oXSL2 = Server.CreateObject("Microsoft.XMLDOM")
 
 If objNode.length > 1 Then ' test to see if obj.Node has any data in it.

  set oXSL2 = Server.CreateObject("Microsoft.XMLDOM")
   	
   oXSL2.Async = False
  
   oXSL2.Load(Server.MapPath("leads_retrieve2.xsl")) ' customized XSL file for the transofrm

   ' I have tried this  no go text not support
'For Each Node In objNode
'Document.Write(objNode.text) & "<br />" 
'Next
'

 Response.Write(objNode.transformNode(oXSL2)) 'Transform the XML using the XSL stylesheet

 Response.Write("I got to here") ' step over test

 Else

 Response.Write("No Leads to Return")
 End If

  
End If

%>

Open in new window

<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="leads_xml.xml" -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="API/leads">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Leads Retrieve NodeSelect</title>
</head>
<body>
<table border="1">
<tr bgcolor="#eeeeee">
<th align="left">Account Name</th>
<th align="left">source_id</th>
</tr>
<xsl:for-each select="leads_item">
<tr>
<td><xsl:value-of select="account_name"/></td>
<td><xsl:value-of select="source_id"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Open in new window

0
Comment
Question by:Cmedic_techs
  • 5
  • 3
8 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34944016
You're trying to call transformNode on an IXMLNode object, which is invalid. You have to call it on the Document object itself.
0
 

Author Comment

by:Cmedic_techs
ID: 34944179

 Response.Write(objNode.transformNode(oXSL2)) 'Transform the XML using the XSL stylesheet

the document object being?  I'm sorry but little new to this, I've slowly built this through various examples out there on the web, and I'll admit, I have not reached full comprehension yet.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34944622
oXML is the document object which holds your XML.
oXSL is also a document object, which in your code holds your XSL document.

SelectSingleNode and SelectNodes both return node objects, which represent elements within the document, rather than the whole document itself.
0
 

Author Comment

by:Cmedic_techs
ID: 34944981
Alright that makes sense, so now I will research based on that, and see if I can figure out how to transform after a SelectNodes is used.

cross your fingers, I've been trying to get past this point for over ten hours already.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Cmedic_techs
ID: 34945013
Set objNode = oXML.SelectNodes("API/leads/leads_item[source_id='Other']")

I need to output this result, hopefully using a xsl stylesheet.
as embededd above.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34945110
You don't need to do a SelectNodes call first. The XSL Transform acts on the whole document. If you want to filter and only display certain elements from your XML document then you need to build that logic into your transform.
0
 

Author Comment

by:Cmedic_techs
ID: 34945499
anyhow.  I'm going to give you the points.  since you responded. and I didn't clarify why I needed to do the SelectNodes in the manner that I was.

but what I was trying to accomplish, is this, and I'm terrible sometimes at writing this out.

client logins.
retrieve leads from remote api in xml format.
select only those leads_items that correspond to that client.
output in a table, the data in that node.
since I can't put asp in the xsl.
I had act on the data prior to the xsl.

I have since found another way to do it that is working.  so thanks anyways.

0
 

Author Closing Comment

by:Cmedic_techs
ID: 34945506
it wasn't actually a solution, it was more a what you were doing wrong, without an example of what to do to resolve it
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now