This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Perl and MSXML3 to transform XML with XSL
- To: XSL-List at lists dot mulberrytech dot com
- Subject: [xsl] Perl and MSXML3 to transform XML with XSL
- From: James Garriss <jpgarriss at home dot com>
- Date: Fri, 19 Oct 2001 09:47:58 -0400
- Reply-To: xsl-list at lists dot mulberrytech dot com
No, using Perl and MSXML3 wasn't my first choice. Yes, it does work. For
background, here is an excellent article from xml.com:
http://www.perl.com/pub/a/2001/04/17/msxml.html
This article shows enough details to load an XML document (and an XSL
stylesheet) into a DOMDocument:
# Load the XML file
$doc_to_transform->{async} = "False";
$doc_to_transform->{validateOnParse} = "True";
$boolean_Load = $doc_to_transform->Load($xml_file);
I have figured out how to get detailed error checking out of the two
loads. The $doc_to_transform->{parseError} syntax gets me access to line
numbers, error reasons and so on. Very nice.
if(!$boolean_Load)
{
# The error message includes file name, line #, position #, and reason.
PrintMessage("error at line ".$doc_to_transform->{parseError}->{line}."
position ".$doc_to_transform->{parseError}->{linePos}." reason
".$doc_to_transform->{parseError}->{reason});
}
The article also shows how to transform them and save the result:
# Perform the transformation and save the resulting DOM object to file
$doc_to_transform->transformNodeToObject($style_sheet_doc, $transformed_doc);
$transformed_doc->save("$out_file");
Unfortunately the article gives me no hint on how to error check the
transformNodeToObject, and I've been unable to figure it out on my own.
The closest example I have found is from MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmcondetecthandlxslerrors.asp?frame=true
They give some JScript examples along this line for transformNode:
try
{
result = source.transformNode(style.XMLDocument);
}
catch (exception)
{
result = reportRuntimeError(exception);
}
Which calls this function:
function reportRuntimeError(exception)
{
return "XSL Runtime Error" + exception.description;
}
What is the equivalent of this try/catch in Perl? I assume the syntax is
something like:
# Perform the transformation and save the resulting DOM object to file
$doc_to_transform->transformNodeToObject($style_sheet_doc, $transformed_doc)
or $transformed_doc->{runtimeError}->{description};
This doesn't work; the "or" is always triggered. Any help is appreciated.
--James Garriss (MITRE)
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list