Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP XML
|
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2003, 01:40 PM
Registered User
 
Join Date: Nov 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Server side transformation with- XSL/XML, ASP, IIS

Hi guys,

I'm having problems getting a server side xsl transformation of an xml file to work. I'm using ASP with IIS to try to spit out HTML, but I'm really stuck. I think my code is ok, but I'm wondering if I've got the right parsers etc. on my machine. I must admit to being a bit lost as to what I need and where it should go. Here are short source files I've been using to attempt the transformation:
------
ASP
------
<%@ LANGUAGE=JScript %>
<html>
<head></head>
<body>
<%
var sourceFile = Server.MapPath("data.xml");
var styleFile = Server.MapPath("data.xsl");

var source = Server.CreateObject("MSXML2.DOMDocument");
var style = Server.CreateObject("MSXML2.DOMDocument");

source.async = false;
source.resolveExternals = false;
source.load(sourceFile);

style.async = false;
style.resolveExternals = false;
style.load(styleFile);


Response.Write(source.transformNode(style));

%>

</body>
</html>
------
XSL
------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="uri:xsl">
<xsl:template match="/">

<table>
<tr>
<td>Title</td>
<td>Author</td>
</tr>

<xsl:for-each select="CATALOG/BOOK">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:for-each>
</table>
</xsl:template>

<xsl:template match="BOOK">
    <td><xsl:value-of select="TITLE"/></td>
    <td><xsl:value-of select="AUTHOR"/></td>
</xsl:template>
</xsl:stylesheet>
------
XML
------
<?xml version="1.0"?>
<CATALOG>
<BOOK>
<TITLE>Introduction to talking shy</TITLE>
<AUTHOR>John Crop</AUTHOR>
</BOOK>

<BOOK>
<TITLE>Introduction to walking</TITLE>
<AUTHOR>John Walk</AUTHOR>
</BOOK>

<BOOK>
<TITLE>Introduction to eating crisps</TITLE>
<AUTHOR>John Fug</AUTHOR>
</BOOK>

<BOOK>
<TITLE>Introduction to smelling like a dog</TITLE>
<AUTHOR>John Acs</AUTHOR>
</BOOK>

</CATALOG>
------
The output is simply the unformatted table headings: "Title Author"

I'd appreciate any tips you might have!

Thanks-
K
 
Old November 8th, 2003, 06:17 AM
Registered User
 
Join Date: Nov 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...And even more curious-
When I 'view source' of the resulting document, I get a table with the correct headings and a row for each line of data in the xml file, but no actual data from the xml file! Every row is blank.

Stuck.

K
 
Old November 10th, 2003, 10:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Its just a problem with your stylesheet not matching what you expect it to match. The problem is that the line <xsl:for-each select="CATALOG/BOOK"> changes the context to each BOOK node in turn. Then you have <xsl:apply-templates/> with no select attribute so you get the default behaviour which is to apply templates to all child nodes of the context node (BOOK). The only child nodes are TITLE and AUTHOR which have no templates specified so again you get the default behaviour which is to output the text of each node. The BOOK template never gets called! So you end up with HTML like this for each BOOK:
<tr>Introduction to talking shyJohn Crop</tr>
This HTML has no <td> tags so the browser doesn't display it properly.

Try this instead:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <table>
      <tr>
        <td>Title</td>
        <td>Author</td>
      </tr>
      <xsl:apply-templates select="CATALOG/BOOK"/>
    </table>
  </xsl:template>
  <xsl:template match="BOOK">
    <tr>
      <td>
        <xsl:value-of select="TITLE"/>
      </td>
      <td>
        <xsl:value-of select="AUTHOR"/>
      </td>
    </tr>
  </xsl:template>
</xsl:stylesheet>
hth
Phil
 
Old November 10th, 2003, 10:14 AM
Registered User
 
Join Date: Nov 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Phil- It works.

K





Similar Threads
Thread Thread Starter Forum Replies Last Post
xml transformation to wml using asp.net arunagottimukkala ASP.NET 1.0 and 1.1 Professional 1 November 7th, 2007 07:23 AM
Newbie: ASP.NET/XML Transformation Problem kwilliams ASP.NET 2.0 Basics 1 August 28th, 2006 02:40 PM
XSLT transformation from XML buffer and XSL file sundaramkumar Javascript 1 September 5th, 2005 02:11 AM
Server side xsl transformation problems (ASP, IIS) kenneth02 All Other Wrox Books 0 November 7th, 2003 01:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.