473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

ASP Include of an XML file

VBH
This is probably a silly question but...

I have an XML file which processes quite happily with XSL when opened on
its own.

However, I just want to include it in an ASP file. But when I do an
SSI, the XML is not reformatted by the XSL.

As in:
<!-- #INCLUDE FILE="2003-06.XML" -->

The XML file includes
<?xml-stylesheet type="text/xsl" href="blog2.xsl"?>

Which works fine when the XML file is opened on its own. However when I
try it as an SSI, I just get the text as one long string.

Its for a site front page and is the XML blog for "what's new". I've
written my own blogging app which outputs xml files. I don't want to
put a load of processing into the front page that I have already handled
with XSL.

So how do you do an ASP SSI of an XML document and get it to fire the XSL?

Any suggestions?

TIA
--------------------
VBH
Jul 19 '05 #1
3 3852
*VBH* wrote:
This is probably a silly question but...
It's not a silly question.
I have an XML file which processes quite happily with XSL when opened
on its own.
'quite happily' depends on whether or not the client has an XML parser
and XSLT processor available!
However, I just want to include it in an ASP file. But when I do an
SSI, the XML is not reformatted by the XSL.

As in: <!-- #INCLUDE FILE="2003-06.XML" -->

The XML file includes <?xml-stylesheet type="text/xsl"
href="blog2.xsl"?>

Which works fine when the XML file is opened on its own. However
when I try it as an SSI, I just get the text as one long string.
Because the client has not received a valid XML document (I'm assuming
that your page does not just consist of the include statement - if it
does then the problem you describe is probably a content-type problem
instead)
Its for a site front page and is the XML blog for "what's new". I've
written my own blogging app which outputs xml files. I don't want to
put a load of processing into the front page that I have already
handled with XSL.

So how do you do an ASP SSI of an XML document and get it to fire the
XSL?


Here's what I do for this exact same process:

if (XMLFileHasBeenUpdatedSinceLastTime) {
TransformTheXMLIntoHTML();
SaveTheResultOfThisTransformationToDisk();
Response.Write(theResultOfTheTransformation)
}
else {
Server.Execute(outputFromPreviousTransformation)
}
I can post all of the necessary script if you like - it's JScript ASP
and there's quite a bit of it. To start with, here's just the
transformation function I use to transform the XML via XSLT into
(X)HTML:

(I'm posting this with word-wrap turned off, but some newsreaders may
still wrap it)
function TransformXMLWithAddParam(xmlFilePath, xslFilePath, paramName, paramValue) {
try {
var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xmlObj = new ActiveXObject("Msxml2.DOMDocument.4.0");
xmlObj.async = false;
xmlObj.resolveExternals = false;
var xmlDoc = xmlObj.load(xmlFilePath);
if (!xmlDoc) {
throw new Error(1, "Unable to load XML file \"" + xmlFilePath + "\"");
}
if (xmlObj.parseError.errorCode != 0) {
throw new Error(2, "\"" + xmlObj.parseError.reason + "\", line=" + xmlObj.parseError.line);
}
else {
// Load style sheet.
var xslObj = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0" );
xslObj.async = false
xslObj.resolveExternals = false;
xslObj.load(xslFilePath);
xslt.stylesheet = xslObj;
if (!xslObj) {
throw new Error(3, "Unable to load XSL file \"" + xslFilePath + "\"");
}
if (xslObj.parseError.errorCode != 0) {
throw new Error(4, "\"" + xslObj.parseError.reason + "\", line=" + xslObj.parseError.line);
}
else {
// Add parameter to XSL sheet
var xslProc = xslt.createProcessor();
xslProc.input = xmlObj;
if (typeof paramName == "string") {
// STRING PARAMETERS USED
xslProc.addParameter(paramName, paramValue);
}
else if (typeof paramName == "object") {
// ARRAY PARAMETERS USED
for (var i in paramName) {
xslProc.addParameter(paramName[i], paramValue[i]);
}
}
xslProc.transform();
return(xslProc.output);
}
}
}
catch (err) {
throw new Error(err.number, "Function TransformXMLWithAddParam() failed with parameters xmlFilePath=\"" + xmlFilePath + "\", xslFilePath=\"" + xslFilePath + "\", paramName=\"" + paramName + "\", paramValue=\"" + paramValue + "\". Message=\r\n" + err.description);
}
}

--
Andrew Urquhart
- FAQ: http://www.aspfaq.com
- Contact: http://andrewu.co.uk/contact/
Jul 19 '05 #2
VBH wrote:
This is probably a silly question but...

I have an XML file which processes quite happily with XSL when opened
on its own.

However, I just want to include it in an ASP file. But when I do an
SSI, the XML is not reformatted by the XSL.

As in:
<!-- #INCLUDE FILE="2003-06.XML" -->

The XML file includes
<?xml-stylesheet type="text/xsl" href= "blog2.xsl" ?>

Which works fine when the XML file is opened on its own. However
when I try it as an SSI, I just get the text as one long string.

Its for a site front page and is the XML blog for "what's new". I've
written my own blogging app which outputs xml files. I don't want to
put a load of processing into the front page that I have already
handled with XSL.

So how do you do an ASP SSI of an XML document and get it to fire the
XSL?
Any suggestions?

TIA
--------------------
VBH


Use the transformNode method of the dom document to transform the document.
(you'll have to remove the ?xml-stylesheet tag)

set xmldoc=createobject("msxml.domdocument")
xmldoc.load("2003-06.XML")
set xsldoc=createobject("msxml.domdocument")
xmldoc.load("blog2.xsl")
response.write xmldoc.transformnode(xsldoc)

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #3
VBH
Bob Barrows [MVP] wrote:
VBH wrote:
This is probably a silly question but...

I have an XML file which processes quite happily with XSL when opened
on its own.

However, I just want to include it in an ASP file. But when I do an
SSI, the XML is not reformatted by the XSL.

As in:
<!-- #INCLUDE FILE="2003-06.XML" -->

The XML file includes
<?xml-stylesheet type="text/xsl" href= "blog2.xsl" ?>

Which works fine when the XML file is opened on its own. However
when I try it as an SSI, I just get the text as one long string.

Its for a site front page and is the XML blog for "what's new". I've
written my own blogging app which outputs xml files. I don't want to
put a load of processing into the front page that I have already
handled with XSL.

So how do you do an ASP SSI of an XML document and get it to fire the
XSL?
Any suggestions?

TIA
--------------------
VBH

Use the transformNode method of the dom document to transform the document.
(you'll have to remove the ?xml-stylesheet tag)

set xmldoc=createobject("msxml.domdocument")
xmldoc.load("2003-06.XML")
set xsldoc=createobject("msxml.domdocument")
xmldoc.load("blog2.xsl")
response.write xmldoc.transformnode(xsldoc)

Bob Barrows


I'd just come to that conclusion. I was hoping I was making some simple
syntactic error. At least this little chunk of code is not too excessive :)

Thanks
--------------------
VBH
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: mescaline | last post by:
Hi, Suppose a_file.cpp contains a function a_function() Now to include it in main_file.cpp I just do #include "a_file.cpp" and I'm all set. i recently came across this seemingly roundabout...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
28
by: Ramesh | last post by:
Hi, I am currently maintaining a legacy code with a very very large code base. I am facing problems with C/C++ files having a lot of un-necessary #includes. On an average every C/C++ file has...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
9
by: bill | last post by:
Forget the exact definition of difference between, #include <foo.h> and #include "bar.h" Normally foo.h is a standard header file, so it's path is not defined in compiler option, but I...
12
by: Francois Grieu | last post by:
Can #include safely use a preprocessing token, as in #define HEADERFILE "stdio.h" #include HEADERFILE int main(void) {return printf("Hello, world\n")*0;} TIA, François Grieu
9
by: zolli | last post by:
Hi, I've been banging my head against this for a while now. Hoping someone here can shed some light on what's going on. On including stdlib.h in a file, I'm seeing the following errors: ...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.