[Openroad-users] Problems with XSL Transformation stylesheet

Antill, Jim jantill at revenue.ie
Tue Aug 14 22:27:47 EST 2007


Martin,
 
Been having a play with MSXML here and I've got it transforming both versions
of your XML (without schemas) correctly. I built the ext. userclass "msxml"
in OR to use versions 2.6, 3.0 and 4.0 of MSXML but couldn't be certain about
the version of the transfomation engine being used.
 
The code is at the end of this mail. The test frame has two multi-line entry
fields working_sef and transform_sef that reference StringObjects. One
problem I did have was that the frame crashed each time it was exited. Could
be to do with our OR patch though. Did you get this problem?
 
This leads me to wonder if the problem is to do with the XML itself or is it
something to do with the StringObject that is passed into your procedure? You
could test this by running my code within a frame and seeing if that worked.
 
Regards,
Jim
 
Here's the code I used (placed behind a button in a frame):
 
on click=
declare
 so_tmp = StringObject;
 so_xsl = StringObject;
 xmlin = StringObject;
 xmlout = StringObject default NULL;
enddeclare
begin
 // Read in the XML File and display it in a field called working_sef
 xmlin.FileHandle = 'd:\martin\notworking.xml';
 working_sef = xmlin;
 field(working_sef).UpdField();
 
 l_domxml = msxml!domdocument.create();
 l_domxsl = msxml!domdocument.create();
 
 // load transformation stylesheet
 so_xsl.filehandle = 'd:\martin\sample.xslt';
 
 // set XML parameters
 l_domxml.async = 0;
 l_domxml.validateOnParse = 0;
 l_domxml.resolveExternals = 0;
 l_domxml.preserveWhiteSpace = 0;
 
 // set XSL parameters
 l_domxsl.async = 0;
 l_domxsl.validateOnParse = 0;
 l_domxsl.resolveExternals = 0;
 l_domxsl.preserveWhiteSpace = 0;
 
 // read files into MSXML objects
 l_domxml.LoadXML(xmlin);
 l_domxsl.LoadXML(so_xsl);
 
 // do the transformation
 so_tmp = l_domxml.TransformNode(l_domxsl);
 
 xmlout = so_tmp.Duplicate();
 
 // Display the output document.
 transform_sef = xmlout;
 field(transform_sef).UpdField();
end;


-----Original Message-----
From: openroad-users-bounces at peerlessit.com
[mailto:openroad-users-bounces at peerlessit.com]On Behalf Of Bloomfield, Martin
(PSD)
Sent: 14 August 2007 12:39
To: International OpenROAD Users
Subject: Re: [Openroad-users] Problems with XSL Transformation stylesheet


*************************************

This e-mail has been received by the Revenue Internet e-mail service. (IP)

*************************************
	

Jim,

 

Thanks for the suggestion.  I'm doing the transformation within the
IiXmlPreProcess part of OpenROAD's XMLin function.  This is called
automatically as part of a call to a GSCP call.  To do the transformation I'm
using Microsoft's MSXML control, version 6.   The code for this is as below.

 

I've tried stripping out the references to the schemas, but this is making no
difference.  As a work-around, we are currently using the "Assign XSL"
function in XMLSpy to "pretty-print" the file before loading it into the
database.

 

PROCEDURE IiXmlPreProcess (b_so_preprocessxml = StringObject DEFAULT NULL,

) =

DECLARE

  l_domxml = msxml!domdocument DEFAULT NULL;

  l_domxsl = msxml!domdocument DEFAULT NULL;

  so_xsl = StringObject;

  so_tmp = StringObject;

  loc1 = integer not null;

  loc2 = integer not null;

ENDDECLARE

{

  l_domxml = msxml!domdocument.create();

  l_domxsl = msxml!domdocument.create();

 

// remove references to schemas - causes transform to fail

  loc1 = b_so_preprocessxml.LocateString(Match = 'xmlns', StartPosition = 1);

  IF loc1 > 0 THEN

    loc2 = b_so_preprocessxml.LocateString(Match = '>', StartPosition =
:loc1);

 

    so_tmp = b_so_preprocessxml.ExtractString(StartPosition = 1, Length =
loc1 - 1);

    so_tmp.ConcatString(string =
b_so_preprocessxml.ExtractString(StartPosition = loc2, Length =
b_so_preprocessxml.Length - loc2));

    b_so_preprocessxml = so_tmp.Duplicate();

    so_tmp.RightTruncate();

  ENDIF;

 

// load transformation stylesheet

  so_xsl.filehandle = XSLTransform;

 

// set XML parameters

  l_domxml.async = 0;

  l_domxml.validateOnParse = 0;

  l_domxml.resolveExternals = 0;

  l_domxml.preserveWhiteSpace = 0;

 

// set XSL parameters

  l_domxsl.async = 0;

  l_domxsl.validateOnParse = 0;

  l_domxsl.resolveExternals = 0;

  l_domxsl.preserveWhiteSpace = 0;

 

// read files into MSXML objects

  l_domxml.LoadXML(b_so_preprocessxml);

  l_domxsl.LoadXML(so_xsl);

 

// do the transformation

  so_tmp = l_domxml.TransformNode(l_domxsl);

 

  b_so_preprocessxml = so_tmp.Duplicate();

 

  l_domxml = NULL;

  l_domxsl = NULL;

}

 

Martin Bloomfield. 

 

From: openroad-users-bounces at peerlessit.com
[mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Antill, Jim
Sent: Tuesday, August 14, 2007 9:57 AM
To: International OpenROAD Users
Subject: Re: [Openroad-users] Problems with XSL Transformation stylesheet

 

Martin,

 

I've given this another go, removing the schemas from the document and both
documents transform in exactly the same way.

 

Can I ask which transformation engine you're using? The XMLSpy tool uses a
custom built-in one.

 

One thing to watch out for is if any odd characters are creeping into the
document that isn't pretty-printed, so the print format is a bit of a
red-herring. In this case I would have expected some transformation errors to
be output though.

 

Finally, can you programatically run XPath queries against the documents
after they've been loaded up? If so then it might be useful to run a few to
test that the XPath statements used in the XSLT are picking up the same nodes
in each document. This would also check that the non-pretty-print version of
the document is being loaded up correctly, which does sound like where the
problem lies.

 

Regards,

Jim

 

Department for Environment, Food and Rural Affairs (Defra)



This email and any attachments is intended for the named recipient only.

If you have received it in error you have no authority to use, disclose,

store or copy any of its contents and you should destroy it and inform

the sender.

Whilst this email and associated attachments will have been checked

for known viruses whilst within Defra systems we can accept no

responsibility once it has left our systems.

Communications on Defra's computer systems may be monitored and/or

recorded to secure the effective operation of the system and for other

lawful purposes.



************************

This message has been delivered to the Internet by the Revenue Internet e-mail service (OP)

*************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.peerlessit.com/pipermail/openroad-users/attachments/20070814/6a9eacc4/attachment.html 


More information about the Openroad-users mailing list