XML and XSL

Associate
Joined
25 Dec 2002
Posts
1,540
Location
South GLOUCESTER
Hi guys

I've been given access to this information system.

I am writing an ASP application to interface with it.

It uses an API which talks in XML. Basically all requests to the API are made in XML. I use the MSXML2.ServerXMLHTTP component to post my XML request to it. I get a response back in the form of XML.

I have decided to use XSL to manipulate the XML into the existing HTML. However its actually getting it to work together i am having problems with.

here is my code:

Code:
set objServerXML = Server.CreateObject("MSXML2.ServerXMLHTTP")

	objServerXML.Open "POST", xmlrequesturl, False
	objServerXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	objServerXML.Send xmlrequeststring

if objServerXML.status = 200 Then 

	Set objxml = Server.CreateObject("MSXML2.DOMDocument") 
	objxml.async = False 
	objxml.load(objServerXML.ResponseText) 

	Set objxsl = Server.CreateObject("MSXML2.DOMDocument") 
	objxsl.async = False 
	objxsl.load(xslstyle) 

	Response.Write objxml.transformnode(objxsl)

Thats just a snippet of code responsible for doing this.

I get the following error when i run it:

The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document

Here is my xsl code:

Code:
xsl1 = _

	"<?xml version=""1.0"" encoding=""UTF-8""?> " & _
	"<html xsl:version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" xmlns=""http://www.w3.org/1999/xhtml"">" & _
	"<xsl:for-each select=""XMLRequest/SearchResults"">" & _
  		"<xsl:value-of select=""Business number"" />" & _ 
  		"<xsl:value-of select=""name"" />" & _ 
  		"<xsl:value-of select=""address"" />" & _  
  		"<xsl:value-of select=""status"" />" & _ 
  		"<xsl:value-of select=""scoreAvailable"" />" & _ 
  	"</xsl:for-each>"

As you can see i have included this in the same page for testing purposes. I submitting this to the function i created to query the API and get a response. Then the function takes that response and tries to transform it.

any help on this would be greatly appreciated. until a day ago i didn't know anything about xml and spent a few hours doing a crash course in it! i understand not everyone will be familiar with the xsl, but if anyone has any info on it id like to hear from you.

Cheers!
 
I *think* your XSL might be slightly wrong, it seems to be missing an actual <xsl:stylesheet> open and close node at least. Here's an example .xsl from a cd-catalog type thing I had lying around (done quite some time ago - don't do this every day...) Maybe it helps:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <xsl:template match="/">
    <HTML>
      <BODY STYLE="font-family:Arial, helvetica, sans-serif; font-size:12pt">
        <xsl:for-each select="catalog/cd">
                  
          <DIV STYLE="background-color:red; color:white; padding:4px">
            <SPAN STYLE="font-weight:bold; color:white">
              <xsl:value-of select="title"/> 
               - 
               <i>
                <xsl:value-of select="artist"/>
              </i>
            </SPAN>
          </DIV>
          <DIV STYLE="margin-left:40px; margin-bottom:1em; font-size:10pt">
                  Country - <xsl:value-of select="country"/>
            <br/>
                       Recording Year - <xsl:value-of select="year"/>
            <br/>
            <SPAN STYLE="font-style:italic">
                      (<xsl:value-of select="company"/>,   $<xsl:value-of select="price"/>)
                  </SPAN>
          </DIV>
          <div>
            <table width="75%" align="center">
              <thead>
                <tr>
                  <th align="right" width="10%">No.</th>
                  <th align="left">Track title</th>
                  <th align="right">Length Sec.</th>
                </tr>
              </thead>
              <tbody>
                <xsl:for-each select="track">
                  <tr>
                    <th align="right"><xsl:value-of select="trackno" /></th>
                    <td>
                      <xsl:value-of select="trackname"/>
                    </td>
                    <td align="right">
                      <!--<xsl:value-of select='format-number(tracklength div 60,  "00m")' /> -->
                      <!--<xsl:value-of select='format-number(tracklength mod 60,  "00sec")' />-->
                      <xsl:value-of select="tracklength"/>
                    </td>
                  </tr>
                </xsl:for-each>
                  
                <tr valign="top">
                  <td ></td>                
                  <th align="right">
                    <!--Total play time -->
                  </th>
                  <td align="right"> 
                        <!-- <xsl:value-of select="sum(track/tracklength)" /> -->
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
          <hr />          
        </xsl:for-each>
      </BODY>
    </HTML>
  </xsl:template>
</xsl:stylesheet>
 
thanks for your help.

i've got a feeling i have several problems with my xsl. the code at the top works fine as i tested it with some proven xml and xsl. i rewrote it after i looked at some more examples and it was half working but not completely.

reason is because basically my xsl was reading data between elements when the response xml wasn't in that layout. instead it uses single elements for each record with attributes inside. i must find a way to read each attribute inside instead. i've not got a clue to be honest! but i was speaking to one of the developers at work and he's going to bring a couple books in for me on the subject which should hopefully steer me in the right direction!

it's all coming together slowly!
 
Back
Top Bottom