XMLTransform Objects |
Active Web |
The XMLTransform object is used in conjunction with the XMLTemplate Object to perform XSLT (Extensible Stylesheet Language Transformations). XSLT is a functional programming language which specifies the rules by which to transform an XML document into another text document, which maybe, but not necessarily an XML document.
An XML transformation requires two inputs the XSLT and the XML document to transform. The XMLTransform Object is obtained from calling the newTransform method on an XMLTemplate object that has been constructed with an XSLT file. The XMLTransform object can then be requested to process transformation on either a file, string or URL the result being the output text document. The advantage of this tiered approach is that the threadsafe XMLTemplate objects, which will tend to be static, can be cached and then reused for multiple transformations.
Property |
Description |
error |
An error message If an error has occurred. If no error has occurred then it will be null. The error messages are explained below: Insufficient number of parameters - A method has been called without the correct number of arguments. No transform available.- The XMLTemplate parameter was missing from a method call. Unable to resolve parameter to file– The file parameter sent to the transformFile method was unable to be resolved to a file. Failed to get resource as stream– The file parameter sent to the transformFile method resolved to a file, but that file could not be opened. While accessing files the operating system can generate various other error messages. |
prototype |
A reference to the Object Prototype. This property does not enumerate and can not be deleted, but it can be changed. |
Function |
Description |
transformFile (file) |
Returns a string which is the result of transforming the file parameter using the XMLTemplate which produced this XMLTransform Object. Or returns false if an error occurred, check the error property for details |
transformString(string) |
Returns a string which is the result of transforming the string parameter using the XMLTemplate which produced this XMLTransform Object. Or returns false if an error occurred, check the error property for details |
transformURL(url) |
Returns a string which is the result of transforming the url parameter using the XMLTemplate which produced this XMLTransform Object. Or returns false if an error occurred, check the error property for details |
setParameter(string,object) |
Allows parameters to be set for the XMLTransform. Each parameter is set by specifying a name for the parameter and an object, the named object may then be accessed in the XSL. |
setStringParameter(string,object) |
As setParameter, but the object parameter is any Active Web script object, whose string value will set as the parameter |
getParameter(string) |
Returns the parameter set in the transform with the given string name. |
clearParameters |
Clears all parameters set against the XSLTemplate. |
There is no constructor for this object, it may only be constructed via a newTransform method call to an XMLTemplate object.
var xTemplate = new XMLTemplate(myXSL.xsl);
var xTransform = xTemplate.newTransform();
The resultant XMLTransform object may then be used to make transformations, based on the XSL provided to the XMLTemplate.
var transformed = xTransform.transformFile(“something.xml”)
Shown below is the XMLTransform object prototype chain.
The XMLTransform objects are not thread safe so you should not put XMLTransform objects into a common repository where they could be potentially used by more than one page executing concurrently. |
Topic ID: 150119