• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1018
  • Last Modified:

xml, xsl on the server, done in classic asp help needed

Hi
I realy need some help.  I am pretty confused on how to translate xml with xsl on  an IIS server using asp.  I want to use the latest version of the parser I think.  I have all versions up to 4.0  installed.  There is a ton of documentaion out there but it I keep coming up with different conclusions and there all wrong.  Please help me fix this code, and understand what the heck I am doing wrong.
I know this looks like crap, but My Brain is fried and this was the best I could come up with, to show what I need to do.
Thanks

<%
  Response.Buffer = True
  Dim objXMLHTTP, xml
  Dim xtext
  Dim ReqString

' building string to send to remote address here

    ReqString = "<XML_to the remote_server>"

      Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

      xml.Open "POST", "http://www.remoteserver.com:80/xmlservlet", False
      xml.setRequestHeader "Content-Type", "text/xml"
      xml.send ReqString
 
%>


<%  
'xml response put into variable here

       xtext = xml.responsetext

'Load the XML here
            set xml = Server.CreateObject("Microsoft.XMLDOM")
            xml.async = false
            xml.load (xtext)
'Load the XSL here
            set xsl = Server.CreateObject("Microsoft.XMLDOM")
            xsl.async = false
            xsl.load(Server.MapPath("test.xsl"))

' write the translated info here
            Response.Write(xml.transformNode(xsl))
%>
0
framos1
Asked:
framos1
  • 23
  • 21
  • 2
1 Solution
 
PeterCiuffettiCommented:
Have you tried using:

xtext = xml.responseXML

If you know the response is supposed to be XML, this is recommended over responseText or responseBody.

This will give a parsed response.  And if the parse fails, access to a parse error through a document object:

If xtext.parseError.errorCode <> 0 Then
   Response.Write("Parse Error line " & xtext.parseError.line & ", character " & _
       xtext.parseError.linePos & vbCrLf & xtext.parseError.srcText)
End If


0
 
framos1Author Commented:
Thanks for jumping in here.
I tried a few different things with what you poited me to.  It's doesn't like xml.responseXML  
I get the following error code on the change:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method

/testing_stuff/xml_files/xmlworking.asp, line 39

any thoughts?


0
 
rdcproCommented:
"Microsoft.XMLDOM" is the old version 2 parser.  Don't use it!  

Also, load() expects a stream, not a string.  loadXML() takes a string, but it's not necessary here anyway.  Also, you have BOTH the ServerXMLHTTP and the XML document using the same variable name!


Do this:
<%
  Response.Buffer = True
  Dim objXMLHTTP, xml
  Dim xtext
  Dim ReqString

' building string to send to remote address here

    ReqString = "<XML_to the remote_server>"

      Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

     objXMLHTTP.Open "POST", "http://www.remoteserver.com:80/xmlservlet", False
     objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
     objXMLHTTP.send ReqString
 

'Load the XML here
          set xmlDoc = Server.CreateObject("Msxml2.DomDocument.4.0")
          xmlDoc.async = false
          xmlDoc.load objXMLHTTP.responseBody
'Load the XSL here
          set xsl = Server.CreateObject("Msxml2.DomDocument.4.0")
          xsl.async = false
          xsl.load(Server.MapPath("test.xsl"))

' write the translated info here using IStream, not response.write
          xmlDoc.transformNodeToObject(xsl, Response)
%>


You can also use the ServerXMLHTTP object directly as a DOM object, though some remote servers mess up the response so this fails:

objXMLHTTP.responseXML.transformNodeToObject(xsl, Response)

Regards,
Mike Sharp
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rdcproCommented:
Also, this is how I typically do it (in JScript, though):

<%@ Language=JScript %>
<%
var iStartPage, iRecordsPerPage


sData = Server.MapPath("Customers.xml")
sXsl = Server.MapPath("Customers.xslt")

var xmlDoc = Server.CreateObject("Msxml2.DomDocument.4.0");
xmlDoc.resolveExternals = false;
xmlDoc.validateOnParse = false;
xmlDoc.async = false;
xmlDoc.load(sData);

var xslDoc = Server.CreateObject("Msxml2.FreeThreadedDomDocument.4.0");
xslDoc.async = false;
xslDoc.load(sXsl);
      
var xslTemplate = Server.CreateObject("Msxml2.XslTemplate.4.0");
xslTemplate.stylesheet = xslDoc;
xslProc = xslTemplate.createProcessor();
xslProc.input = xmlDoc;
xslProc.output = Response;

iStartPage = parseInt(Request.QueryString("startPage"))
if (isNaN(iStartPage) || iStartPage < 1)
{
      xslProc.addParameter("pCurrentPage", 1);
}
else
{
      xslProc.addParameter("pCurrentPage", iStartPage);
}

iRecordsPerPage = parseInt(Request.QueryString("recordsPerPage"))
if (iRecordsPerPage > 4)
{
      if (iRecordsPerPage > 100)
      {
            iRecordsPerPage = 100
      }
}
else
{
      iRecordsPerPage = 10
}
xslProc.addParameter("pRecordsPerPage", iRecordsPerPage);

xslProc.transform();

%>

Not only does this process quickly, but this allows me to:

1.  Use parameters for the transformation.  This can be real handy at times.  This example was set up to do paging of the data.  I often need the current date in the XSLT for calculation-purposes in reports.  I can easily set a parameter in the transformation to provide that.  Other uses--a client side version of the same thing that allows you to select the number of columns in a table:

http://rdcpro.com/Members/rdcpro/snippets/xpathgrouping2/

2.  Cache a pre-compiled XSLT.  This can help on complex transformations, or on sites with many many hits, but doesn't necessarily need to be used.  See:

http://rdcpro.com/Members/rdcpro/snippets/cachingtemplates/

Regards,
Mike Sharp
0
 
framos1Author Commented:
Hi Mike,
Ok, Thanks for setting me straight on the 4.0 parser information.  I am still getting an error.  I am posting the code changes.  It looks like I am now getting an asp error.  It doesn't like line  xmlDoc.transformNodeToObject (xsl, Response)

Everything is exact, except for the server url and the request string.  I will look at the jcsript info after I figure out the asp vbscript stuff.  I have been struggling with XML IIS server side for 2 months, when I finally figured out that the DTD files that we were given for the testing server were old and wrong. I was pretty pissed, so I am trying to stay positive, but I am pretty toasted.

<%
  Response.Buffer = True
  Dim objXMLHTTP, xml
  DIM xtext
  Dim ReqString
   
      ReqString = "<XML_to the remote_server>"
   
   Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
      objXMLHTTP.Open "POST", "http://www.remoteserver.com:80/xmlservlet", False
      objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
      objXMLHTTP.send ReqString
            
'Load the XML
   set xmlDoc = Server.CreateObject("Msxml2.DomDocument.4.0")
      xmlDoc.async = false
      xmlDoc.load objXMLHTTP.responseBody

'Load the XSL
    set xsl = Server.CreateObject("Msxml2.DomDocument.4.0")
      xsl.async = false
      xsl.load(Server.MapPath("test.xsl"))
      xmlDoc.transformNodeToObject (xsl, Response)  <-- error says  "Cannot use a parentheses when calling a Sub"
 %>
0
 
rdcproCommented:
Oh, yeah, that's a VBScript thing.  One of the reason I prefer JScript!  ;^)

Just drop the parentheses, because in VBScript this is a subroutine, not a function, and they seem to think it matters.

Regards,
Mike Sharp
0
 
rdcproCommented:
oh, one comment on using DTDs....they're almost always wrong.  It blows me away, but it's surprising how often companies publish DTDs that are inaccurate or simply mal-formed.  When Interwoven Teamsite 5.0 came out, I had to edit the DTDs because my XML editor (XML Spy) actually uses them.  I'm amazed no-one ever actually tried to validate their XML before the product was released.  They actually provided a perl-based "validator" but IIRC, it validated the XML documents using an invalid DTD!

Regards,
Mike Sharp
0
 
framos1Author Commented:
Ok, you are well on your way to getting a shrine made up in your honor.   New error,  I know it is on the style sheet.  I am grateful to actually be getting legit errors at this point!

Here it is:

msxml4.dll error '80004005'
The "http://www.w3.org/TR/WD-xsl" namespace is no longer supported in this version of MSXML.
/testing_stuff/xml_files/xmlworking.asp, line 44

Here is the beginning of the xsl file I am using:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
      <html>
      <body>

I promise I will start playing around in jscript and I will live at your website and even throw a back-link to it from mine!
-Frank
0
 
PeterCiuffettiCommented:
Hi,

The name space you are using is an ancient form used in in the first MSXML.  Its for the working draft of XSL.  The valid namespace is:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


0
 
rdcproCommented:
This change will almost certainly require re-writing the XSLT as well, as there were a lot of things done differently.  Depending on how complex the stylesheet is, this may be a lot or a little work.

Post the XSL if you're running into troubles.

Regards,
Mike Sharp
0
 
framos1Author Commented:
yupper, I saw one of your old posts. actually it's pretty simple  here it is.  I already added one suggested change from peters post, but I can see a bit more is required.  
Here it is:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
      <html>
      <body>
      <table width="100%"  border="1">
  <tr>
    <th>column 1</th>
    <th>column 2</th>
  </tr>
  <xsl:for-each select="xml_/path/here">
  <tr>
    <td><xsl:value-of select="ID"/></td>
    <td><xsl:value-of select="amt"/></td>
  </tr>
  </xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
0
 
framos1Author Commented:
I just want to start off with  a simple table

-F
0
 
rdcproCommented:
Well, that one is simple enough.  It looks fine to me; is there a problem with it?

Regards,
Mike Sharp
0
 
framos1Author Commented:
Well with all said and none, your code assistance and the line change in the xsl file.  I am back to square one.

I only get the table header and two odd characters: these ----> ÿþ
here is the test link http://beta.axentmicro.com/testing_stuff/xml_files/xmlworking.asp

Let me know what you think

thx
-Frank
 
0
 
rdcproCommented:
A look at the HTML source reveals the problem:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
ÿþ< h t m l > 
 
 < b o d y > 
 
 < t a b l e   w i d t h = " 5 0 % "   b o r d e r = " 1 " >
 
 < t r > 
 
 < t h > c o l u m n   1 < / t h > 
 
 < t h > c o l u m n   2 < / t h > 
 
 < / t r > 
 
 < / t a b l e > 
 
 < / b o d y > 
 
 < / h t m l > 
 
 
<body>
</body>
</html>


The ÿþ is a byte-order-mark, rendered using the ISO-8859-1 character set.  I see a meta tag in the first HTML header that tells the browser what characterset the response is in, but the results of the transform are actually rendered in UTF-16.  You can tell this because of the extra space between each character.  That's because for Latin-1 characters (standard western alphabet), the UTF-16 byte codes all begin with "00".  So the string: "<table" in your code, in UTF-16 is the following set of bytes: "003C 0074 0061 0062 006C 0065".  But your browser thinks it's seeing ISO-8859-1, which then interprets the byte string like:  "00 3C 00 74 00 61 00 62 00 6C 00 65".   Each of these "00" bytes are rendered as whitespace, which the browser collapses when it parses the page.  

This means one of two things:

1  you're probably stll transforming to a string, then using Response.write.  That is, you're still using this:

 write the translated info here
          Response.Write(xml.transformNode(xsl))

instead of one of the transform methods that write to the IStream interface of the response object, like:

 write the translated info here
    xmlDoc.transformNodeToObject  xsl, Response

2. If you're using the second approach, the transform is defaulting to UTF-16, because the processor doesn't know any different.  Actually, I think it defaults to UTF-8, so I'm pretty sure you're using a string for the transform.

In any case, the solution is simple.  Add the correct output tag to your XSLT, to specify ISO encoding (if ISO is really what you want).  Or stick entirely with unicode.  All the web development work I've done for the last few years has been UTF-8, or in a few special cases, UTF-16.  Whenever possible I use stream interfaces rather than strings, because strings are expensive, and they introduce encoding problems (doh!).

Modify your XSLT like:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>


Or use a different encoding for your web page and your transform.  Remember, ISO-8859-1 doesn't have some of the more modern characters, like the Euro symbol.  If you must use an ISO encoding, and can't use UTF-8 or UTF-16, I'd use ISO-8859-15, which has the latin 1 characters, plus some new ones.

Regards,
Mike Sharp
0
 
rdcproCommented:
By the way, the ÿþ is a dead giveaway here, because the character codes for ÿþ are  00FF 00FE.  And the byte codes for the BOM are: FEFF.  But here's the twist.  You're looking at it on a "little endian" machine, so the byte order is reversed.  

Any time you see the characters ÿþ, you can almost be certain this is your problem.

Regards,
Mike Sharp
0
 
framos1Author Commented:
I am not really sure what I am missing on this.  
I hit the book store today to see if I can find any good ref guides to msxml 4.0.
Here is the asp and xsl code so far with suggested changes .     I  didn't know about the encoding.  I would rather use which ever is most compatable.  I use WYSIWYG for laying out the asp pages, so I was using the default on the application and of course I am clueless on the xsl.

I still don't know jack about xsl.  I can tell you I thought translations would be a lot simpler.  I am hoping once I get this figured out, I can actually start doing something productive.  This is driving me a bit nuts.


*************
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%
  Response.Buffer = True
  Dim objXMLHTTP
  Dim xmlDoc
  Dim xsl
  Dim ReqString
    ReqString = "<XML_Posted_to_other_server>"
   
      Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
            objXMLHTTP.Open "POST", "http://xml.server.com:80/xmlservlet", False
            objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
            objXMLHTTP.send ReqString
 %>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<%
'Load the XML
      set xmlDoc = Server.CreateObject("Msxml2.DomDocument.4.0")
            xmlDoc.async = false
            xmlDoc.load objXMLHTTP.responsebody
'Load the XSL
      set xsl = Server.CreateObject("Msxml2.DomDocument.4.0")
            xsl.async = false
            xsl.load(Server.MapPath("test.xsl"))
            xmlDoc.transformNodeToObject xsl, Response
%>
<body>
</body>
</html>
***********************

Here is the XSL code:

*****************
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>
<xsl:template match="/">
      <html>
      <body>
      <table width="50%"  border="1">
  <tr>
    <th>column 1</th>
    <th>column 2</th>
  </tr>
  <xsl:for-each select="XML/path/to/match">
  <tr>
    <td><xsl:value-of select="IDCode"/></td>
    <td><xsl:value-of select="Qty"/></td>
  </tr>
  </xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
***********************************

I only changed a couple of things for the post to protect url info.  I can mail them to you but the server on the other end is locked to IP addressesd anyway.

thx
-Frank
0
 
rdcproCommented:
What does this code produce?  Is there an error, or what?

Also, in the XSLT, you don't need the <html> tags--they're already in your ASP page.
And I'd delete the CODEPAGE from the directive:

<%@ LANGUAGE="VBSCRIPT" %>

Also, you're posting the string:

ReqString = "<XML_Posted_to_other_server>"

to the servlet.  This seems weird to me, expecially since you're tellling the servlet you're sending XML.    If you're supposed to be posting an XML document, this isn't one.  If it doesn't matter, try a GET rather than a POST.  Here's how to send XML:

     Dim ReqString
     ReqString = "<root><foo>bar</foo></root>"
     Set xmlOutgoingDoc = Server.CreateObject("Msxml2.DomDocument.4.0")
           xmlOutgoingDoc.async = false
           xmlOutgoingDoc.loadXML ReqString

     Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
           objXMLHTTP.Open "POST", "http://xml.server.com:80/xmlservlet", False
           objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
           objXMLHTTP.send xmlOutgoingDoc



Regards,
Mike Sharp
0
 
framos1Author Commented:
Error...,kinda sorta. It isn't failing or locking up,  it is just not outputting data into the table.

I figured out how to read/look at the objects in the debugger on the server.  I am going to play with these in the morning.  I found something interesting though.  the response body is coming back as bytes, but the responsetext is coming back looking like xml as a string data type.  it is also converting correctly to xml in the xmldoc xml object.  So,  I think I will be able to dig in better tomorrow.
 FYI, it isn't that I didn't know how to use the script debuger, it's just that there is a lot of old info out there and mixed messages.  I really appreciate you jumping in and filling my brain with all kinds of new things.

-Frank
0
 
rdcproCommented:
>>Error...,kinda sorta. It isn't failing or locking up,  it is just not outputting data into the table.

Ah, well, that could be an entirely different situation.  If you could post an example of the XML, it would help.  If there is a namespace in the returned XML, then that would easily account for the lack of data in the output table.

Regards,
Mike Sharp
0
 
framos1Author Commented:
Can I send it via e-mail?
0
 
rdcproCommented:
Sure,

rdcpro@hotmail.com

Zip it up if it's big, please.

Regards,
Mike Sharp
0
 
framos1Author Commented:
Mike,
Did you ever get that mail I sent?

-Frank
0
 
rdcproCommented:
No I didn't...

Regards,
Mike Sharp
0
 
framos1Author Commented:
I am going to send right now.

Thx

-F
0
 
rdcproCommented:
I still didn't get it.  How big is the attachment?  my email is rdcpro@hotmail.com

Regards,
Mike Sharp
0
 
framos1Author Commented:
Really strange, I sent from 2 addresses and even sent a blank test one.
I zipped it up but it's only like 5k unzipped and resent it 5 min ago

-Frank
0
 
rdcproCommented:
Very strange. I wonder if hotmail has blacklisted the server your email is coming from...

Try sending it to my "private" email address.  It's my first name, Mike and the server is the same as my website, rdcpro.com.  I generally don't publish that email address (to minimize spam), and use my hotmail address for "public" email.  Frankly I don't check the rdcpro email all that often.  

Regards,
Mike Sharp

0
 
framos1Author Commented:
I know what you mean  I was debating setting up a temp address on our server for you.  it is off again!

-F
0
 
rdcproCommented:
Ok, got it at that address.  I'll have a look and get back to you.

Regards,
Mike Sharp
0
 
rdcproCommented:

In your ASP page, Change line 37 to be:

xmlDoc.load objXMLHTTP.responseBody

since load() does not accept a string, and the xml property is a string.

You *could* use

xmlDoc = objXMLHTTP.responseXML

BUT I've found this to be unreliable, since it depends on how the remote server has set the contentType.  So I just load the responseBody into the DomDocument object as in my example above.

Also add this line immediately before line 37:

xmlDoc.resolveExternals = false;

If you need to validate the response from the remote server, you'll have to get a copy of the DTD, and save it so that the server can find it, which is probably going to be in the same directory as the ASP page.  Because this is loading in an ASP page, it may not work anyway--I don't remember how ASP handles external references in a DomDocument object...  



Regards,
Mike Sharp
0
 
framos1Author Commented:
check this out,  from the debugger
objXMLHTTP Object responsebody value is:
      ?????????•????????????????????????????????????????????????????=??????????????????????????†?????????????????????††???????????????????????????????†???????††????????????????††???????????????†††?????????????††???????????????†††???????????†††????????????????†††?????????????????†††?????????????????††??????????????????††????????????????††???????†††???????????????†††???????????????††???????†††?????????????????††††?????????????††???????†††?????????????????††††?????????????††???????†††????????????????†††?????????????†††??????††††????????????????†††???????????????????????????????††??????????????????????????????????????      Variant

yet the responseText      is:
"<?xml version=""1.0"" encoding=""UTF-8""?> "      String     ****you have the response format from the e-mail.

The responseXML is blank but expandable to the nodes.  If that makes sense.

thanks,
-Frank


I know we are close





0
 
framos1Author Commented:
oh yeah,
The code is now like below and I have had the DTD in the directory all along.  Also if you look at the source of the link
http://beta.axentmicro.com/testing_stuff/xml_files/2xmlworking.asp
it looks like it is almost starting to work at least outputting some of the xsl (html)code just no population of data.

<%
'Load the XML
      set xmlDoc = Server.CreateObject("Msxml2.DomDocument.4.0")
            xmlDoc.async = false
            xmlDoc.resolveExternals = false
            xmlDoc.load objXMLHTTP.responsebody
'Load the XSL
      set xsl = Server.CreateObject("Msxml2.DomDocument.4.0")
            xsl.async = false
            xsl.load(Server.MapPath("test.xsl"))
            xmlDoc.transformNodeToObject xsl, Response
%>
0
 
framos1Author Commented:
Well, after learning a crapload of stuff over the past few weeks from you and what I learned from my own research, I think I found a major screwup on my part.  I hope!
As embarrassed as I am to say this, look at the files I sent you.  

First look at the first line of the xml string I am building.  Then take little peak at the xsl file I sent. Which does by the way match the xml response file I sent you.  

If  I am right, (can't test till the morning) .....the live response that I have been trying to translate, would not match the request I am sending.  
Although I hope I am correct, to put an end to this saga, I know I am going to look totally retarded.  

BTW much of my research for answers to off the wall questions to manipulate xml the way I need too, led me to posts or responses of yours. I don't know if I can say this in here, but you are indeed a bad-ass!
How you find the time to answer and publish all that information.

-Frank

0
 
rdcproCommented:
Say, that's weird. My last post never showed up...I'll resend it in the morning. But the XML response you sent does transform correctly with the XSL you sent.  

But this business here:

?????????•????????????????????????????????????????????????????=??????????????????????????†?????????????????????††???????????????????????????????†???????††??????????

looks like encoding problems.  The post I was going to send yesterday has some modified ASP that should fix this. I generally try to avoid sending HTML out to the browser from the ASP page unless I'm abosolutely sure of what encoding I'm using.

and yeah, I'm kind of anal about this XML thing...I wish I had more time for it.

Regards,
Mike Sharp
0
 
framos1Author Commented:
Hi Mike,
I hope you had a good weekend.
Well, I learned a few things this weekend.  None of which is helping me solve this, only circumvent it.
I figured out the difference between .load and loadXML but...  not helping the situation.  
Bascially,  as far as I can tell, the response from the remote server is not loading correctly.

What was the modified ASP you were going to post?  


-Frank
0
 
rdcproCommented:
I'll have to rewrite it...when I got to work, I found that all my dev machines had rebooted, and so I don't have a permanant copy.  But it won't take long...I'll get it posted in a few minutes.
0
 
framos1Author Commented:
BTW I put some points for all the efforts you have put in so far.
title = points for rdcpro

Thanks again,
-F
0
 
rdcproCommented:
Ok, I've got your page working...The XSLT had an incorrect path...use this one:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
      <xsl:template match="/">
            <html>
                  <head>
                        <title>Test</title>
                  </head>
                  <body>
                        <table width="50%" border="1">
                              <tr>
                                    <th>column 1</th>
                                    <th>column 2</th>
                              </tr>
                              <xsl:for-each select="XML_PriceAvailability_Response/Detail/LineInfo/WhseInfo">
                                    <tr>
                                          <td>
                                                <xsl:value-of select="IDCode"/>
                                          </td>
                                          <td>
                                                <xsl:value-of select="Qty"/>
                                          </td>
                                    </tr>
                              </xsl:for-each>
                        </table>
                  </body>
            </html>
      </xsl:template>
</xsl:stylesheet>


Also, I re-wrote the ASP page, but did it in Javascript so that I could incorporate a little better error handling...you'll have to translate to VBScript (assuming you really want to write in in VBScript), but this shows you what you need to do.  I assumed you wanted to hide the URL of the server you're using, so you'll have to change the URL of the remote server to the one you sent me in the email:

<%@ language="JScript"%>
<%
  var objXMLHTTP;
  var xmlOutgoingDoc;
  var xmlDoc;
  var xsl;
  var ReqString;
    ReqString = "<XML_PriceAvailability_Submit><Header>"
    ReqString += "<UserName>22100</UserName><Password>TESTING</Password>"
    ReqString += "<TransSetIDCode>846SEND</TransSetIDCode>"
    ReqString += "<TransControlID>10000</TransControlID>"
    ReqString += "</Header><Detail><LineInfo><AssignedID>001</AssignedID>"
      ReqString += "<RefIDQual>VP</RefIDQual><RefID>349420</RefID>"
    ReqString += "</LineInfo></Detail><Summary><NbrOfSegments>4</NbrOfSegments></Summary>"
    ReqString += "</XML_PriceAvailability_Submit>"

try
{
      xmlOutgoingDoc = Server.CreateObject("Msxml2.DomDocument.4.0")
    xmlOutgoingDoc.async = false;
    xmlOutgoingDoc.loadXML(ReqString)

      objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP");
      objXMLHTTP.open("POST", "http://RemoteServerUrl/XmlServlet", false);
      objXMLHTTP.setRequestHeader("Content-Type", "text/xml");

      objXMLHTTP.send(xmlOutgoingDoc);

      xmlDoc = Server.CreateObject("Msxml2.DomDocument.4.0")
      xmlDoc.async = false
      xmlDoc.resolveExternals = false;
      xmlDoc.validateOnParse = false;
      xmlDoc.load(objXMLHTTP.responseBody)

      xsl = Server.CreateObject("Msxml2.DomDocument.4.0")
      xsl.async = false
      xsl.load(Server.MapPath("the_style_sheet.xsl"))
      xmlDoc.transformNodeToObject(xsl, Response);


}
catch(ex)
{
      Response.ContentType="text/html"
      Response.Write("Error: " + ex.message)
}


%>


This produces the following HTML:

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
</head>
<body>
<table width="50%" border="1">
<tr>
<th>column 1</th>
<th>column 2</th>
</tr>
<tr>
<td>MIAMI, FL</td>
<td>9935</td>
</tr>
<tr>
<td>SWEDESBORO, NJ</td>
<td>0</td>
</tr>
<tr>
<td>SOUTH BEND, IN</td>
<td>0</td>
</tr>
<tr>
<td>FONTANA, CA</td>
<td>0</td>
</tr>
<tr>
<td>DROP SHIP WH</td>
<td>9999</td>
</tr>
</table>
</body>
</html>


Note that if you want to embed the results of the transform into an HTML page as you were doing before, you'll have to set the Content-Type and CharSet manually, like:

  Response.ContentType="text/html"
  Response.CharSet="utf-8"

Place these at the top, before you write any HTML to the page.  If you allow MSXML to write the HTML and HEAD tags, it will automatically put the correct meta tag in the output.  For example, it wrote:

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
</head>
[...]

even though that meta tag isn't in the XSLT!

This solves the encoding issue you were having.

Also, they get rather upset around here if you post additional questions to increase the points above 500, and frankly it doesn't matter to me that much either way.  The main thing about a 500pt question is that it tells me the question is important to the poster.  If I see a 20pt question, I figure they only want a 20pt response.  ;^)

I suggest you post a 0 pt question to the community support area, explain you  didn't know it wasn't allowed, and ask them to delete the extra points question.  


Regards,
Mike Sharp
0
 
rdcproCommented:
Oh, I forgot to mention that as long as you have:

      xmlDoc.resolveExternals = false;
      xmlDoc.validateOnParse = false;

you don't need the DTD in my local folder.  However, at first it seemed like this was not working, as a few times I received an error...Must have been something else wrong, though, as it works fine now without the local DTD.

Regards,
Mike Sharp

0
 
framos1Author Commented:
Thanks mike,  I was able to delete the other question.  I didn't know just wanted to show appreciation.
I will look at the Script in the morning.  I picked up a lot while transforming some of the code to an access module.  earned about many of the goodies available.  
I figured I was going to have to use the Fso object and write an xml file locally(which may be useful also)

Thanks, I'l let you know how i make out.

-Frank
0
 
rdcproCommented:
The FSO won't be available in a web page, unless it's loaded from the local filesystem.  In fact, it may be that you have to make it an HTA page, not HTML to get FSO to work.  Or maybe I misunderstood--if you're doing this from the server side, in ASP, it would work, but it's not really necessary;  Unless you actually need the hard file somewhere, just use streams.  Get your data from the database as a stream, convert it to an XML stream, using the recordset.save(IStreamConsumer, adPersistXML) approach.  Like:

rs.save(xmlDoc, 1)

This produces an XML document from any ADO recordset, useful if you must work with Access.  It does have namespaces, though, so you'll have to declare those in the XSLT.  My website has details on how to handle namespaces in XSLT:

http://rdcpro.com/Members/rdcpro/snippets/xsltandnamespaces/
and
http://rdcpro.com/Members/rdcpro/snippets/groupinggrades/

Regards,
Mike Sharp
0
 
framos1Author Commented:
All of this is being done server side.  For browser compatability.

Actually, I already got the FSO to work and write the xml response to a new XML file.  Don't be to critical of the code though, I was just playing around to see if it could be done as an alternative.  I would just wind up with a bunch of dynamically named xml files in a directory with the xml I need in each. For speed, I would ref the path to the file also.  But I am still Playing.  It's pretty simple though. and may reduce transaction time if I don't have to connect to the remote server for every item.   I really can't dig too far, until I can get past this simple translation.  It may do what I need for some other stuff down the road.

Eventually I will be updating the SQL server on some data and not other that's when I will start really digging, but that isn't important right now.  I am just bummed that I can't get the MSXML4.0 to translate correctly.  It shouldn't be this complex.  I know a book is getting released on the 24th of DEC. but like I said, it shouldn't be this complicated for a simple starter application.
BTW I am looking at the Jscript you put together now.
-Frank

Dim file_name_variable
Dim xml_text_variable
Dim fso
Dim ts
Dim filename
      file_name_variable = 115125
      filename = (file_name_variable &".xml")

'build and save the xml file
      xml_text_variable = objXMLHTTP.responseXML.xml

      Set fso = CreateObject ("Scripting.FileSystemObject")
      Set ts = fso.CreateTextFile(server.MapPath(thevariable& ".xml"))  
            ts.Write CStr(xml_text_variable)
0
 
rdcproCommented:
I was able to get MSXML 4 to translate properly...encoding issues can drive you nuts, but eventually you figure out routine ways of coding that save you the headaches.  The key parts are not assuming what codepage/character encoding you need, and letting the XSLT engine handle the output encoding itself by using stream-based transformations.

I see now what you're using the FSO for.  If you're using it to cache, and the amount of data isn't excessive, you might consider caching in an application object.  I have some sample ASP code for this, although it really deals with caching a precompiled spreadsheet, the code can work just as well for you if you want to cache some of this XML.  In your case, if there are multiple XML documents being cached, make sure you use Application.lock and Application.unlock when you update them--otherwise your users may get one version of one, and a later version of another if they happen to be loading when you're updating.

http://rdcpro.com/Members/rdcpro/snippets/cachingtemplates/

Regards,
Mike Sharp
0
 
framos1Author Commented:
Augggggggghhhhhhhhh!

One line of code fixed it all!!!!!!     one crappy line of code!!!!!  There is no way in hell, I would have ever figured it out, without your help Mike!  

this line----->  xmlDoc.validateOnParse = false  fixed it all.

ok, well not exactly.. but it was the missing piece
both lines really did it.
xmlDoc.resolveExternals = false
xmlDoc.validateOnParse = false

Now I can get into learning the XSLT and the fun stuff dumping to a database.  

-Frank

0
 
rdcproCommented:
Rightous!  

Mike
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 23
  • 21
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now