[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Perl and MSXML3 to transform XML with XSL

Subject: Perl and MSXML3 to transform XML with XSL
From: James Garriss <jpgarriss@xxxxxxxx>
Date: Fri, 19 Oct 2001 09:47:58 -0400
perl transform xml
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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.