Forum Moderators: open

Message Too Old, No Replies

UPS XML Rates & Services

just a little spoon-feeding, please

         

Datado

6:59 pm on Jul 11, 2003 (gmt 0)

10+ Year Member



In March, Macrost posted code that sends a rates request to UPS and catches the response. I have been able to use this code to send a request and receive the response but I get lost in the xsl section. I am unable to transform the xml elements into xhtml variables for further processing. I am brand new to XML so the comments in the code aren't helping me out very much. Do I need to create an xsl file named template? How is it being referenced? Here is Macrost's code...

<% Response.Buffer=True %>
<%
'dim all of our vars
Dim xml, xsl, template, processor, strxml

'you can build the query dynamically by using request.form or request.querystring, however you want to use it
strxml = "<?xml version='1.0'?><AccessRequest xml:lang='en-US'><AccessLicenseNumber></AccessLicenseNumber>
<UserId></UserId><Password></Password></AccessRequest><?xml version='1.0'?>
<RatingServiceSelectionRequest xml:lang='en-US'><Request><TransactionReference>
<CustomerContext>Rating and Service</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference>
<RequestAction>Rate</RequestAction><RequestOption>shop</RequestOption></Request><PickupType>
<Code>01</Code></PickupType><Shipment><Shipper><Address><PostalCode>30076</PostalCode>
</Address></Shipper><ShipTo><Address><PostalCode>30041</PostalCode></Address></ShipTo><Service>
<Code>11</Code></Service><Package><PackagingType><Code>02</Code><Description>Package</Description>
</PackagingType><Description>Rate Shopping</Description><PackageWeight><Weight>33</Weight></PackageWeight></Package>
<ShipmentServiceOptions/></Shipment></RatingServiceSelectionRequest>"

'this will url encode your request
'strxml = Server.UrlEncode(strxml)

'here's where we send the stuff
Dim xmlhttp
Set xmlhttp = Server.CreateObject("MSxml2.ServerxmlHTTP")
xmlhttp.Open "POST","https://www.ups.com/ups.app/xml/Rate?",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send strxml
Response.Write(xmlhttp.responseText)
'we load into a multi thread object for xsl transformations
Set xml = Server.CreateObject("MSxml2.FreeThreadedDOMDocument.3.0")
xml.async = false
xml.loadxml(xmlhttp.responseText)

'start email success
Dim ObjMail, intMailFormat, strSubject
intMailFormat = 1
strSubject = "good response"
If Not xml Is Nothing Then
If Not xml.documentElement Is Nothing Then
'we are looking for the root node.
If xml.documentElement.nodeName = "RatingServiceSelectionResponse" Then
Set ObjMail = Server.CreateObject("CDONTS.NewMail")
ObjMail.FROM = ""
ObjMail.TO = ""
ObjMail.Subject = strSubject
ObjMail.BodyFormat = intMailFormat
ObjMail.Body = "Your request." & vbcrlf & strxml & vbcrlf & "Your response." & vbcrlf & xmlhttp.responseText
ObjMail.Send
Set ObjMail = Nothing
End If
End If
End If

'load our xsl
Set xsl = Server.CreateObject("MSxml2.FreeThreadedDOMDocument.3.0")
xsl.async = false
Set template = Server.CreateObject("MSxml2.XSLTemplate")

'by using template we can dynamically send params to our xsl
template.stylesheet = xsl
set processor = template.createProcessor()
processor.input = xml

'HERE IS WHERE WE SEND PARAMETERS TO THE XSLT TO CONTINUE
'TO BE ABLE TO ACCESS THE PARAM'S IN THE XSL THE FORMAT IS LIKE THIS AT TOP-LEVEL <xsl:param name="arrivalDate"/>
'yourVar = Request.Form("yourVar")
'If yourVar <> "" Then
' processor.addParameter "yourVar", yourVar
'End If
processor.transform()

'Here is the final transformation to the browser, everything is sent downstream
Response.write (processor.output)

Set xsl = Nothing
Set xml = Nothing
Set xmlhttp = Nothing
Set template = Nothing
%>

[edited by: Xoc at 7:02 pm (utc) on Sep. 1, 2003]

macrost

9:43 pm on Jul 11, 2003 (gmt 0)

10+ Year Member



'load our xsl
Set xsl = Server.CreateObject("MSxml2.FreeThreadedDOMDocument.3.0")
xsl.async = false
xsl.Load(Server.MapPath("xsl/filename.xsl"))

Datado

2:09 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



Macrost,

Thank you for your response.

Please let me know if I am grasping this:

By using your original code under 'load our xsl',
you are using template to dynamically send parameters
to the xsl (as you state in your comments). This
way, the xsl file will only need to define the elements
of the node from the UPS response which one wishes to use
as opposed to having to have all of them (the entire node).
Is that correct?

Or, I could create the xsl file to define the entire node
and use only those elements I need, mainly, the total rate
for a single shipment (in my case).

In either case, you would still need to include the reference to the xsl file that you posted in your response?

Thank you again for your assistance.