The following code demonstrates some of the ways that the component can be used to batch process XML into the target output format using an XSL style sheet:
In VBScript in Active Server Pages:
<%
Set objTransform = Server.CreateObject("Stonebroom.XSLTransform")
Dim strStatus 'to hold the status message
strXMLFile = "/data/xml/myfile.xml" 'the XML source file
strXSLFile = "/data/xsl/myfile.xsl" 'the XSL style sheet file
strOutFile = "/results/myfile.html" 'path and name for the resulting disk file
blnWorked = objTransform.TransformXML(strXMLFile, strXSLFile, strOutFile, strStatus)
Response.Write strStatus
%>
In JScript in Active Server Pages:
<SCRIPT LANGUAGE="JScript">
var objDial = Server.CreateObject('Stonebroom.XSLTransform');
var strStatus; // to hold the status message
var strXMLFile = '/data/xml/myfile.xml'; // the XML source file
var strXSLFile = '/data/xsl/myfile.xsl'; // the XSL style sheet file
var strOutFile = '/results/myfile.html'; // path and name for the resulting disk file
blnWorked = objTransform.TransformXML(strXMLFile, strXSLFile, strOutFile, strStatus);
Response.Write(strStatus);
</SCRIPT>
In Visual Basic or VBA:
'you must first add a Reference to the DLL (named 'Stonebroom') to your 'project using the Project|References or Tools|References dialog Dim objTransform As New XSLTransform Dim strStatus As String 'to hold the status message strXMLFile = "/data/xml/myfile.xml" 'the XML source file strXSLFile = "/data/xsl/myfile.xsl" 'the XSL style sheet file strOutFile = "/results/myfile.html" 'path and name for the resulting disk file blnWorked = objTransform.TransformXML(strXMLFile, strXSLFile, strOutFile, strStatus) MsgBox strStatusAlternatively you can provide the XML document as a string, the XSL document as a string, and/or return the result as a string. For example:
Set objTransform = Server.CreateObject("Stonebroom.XSLTransform")
Dim strResult 'to hold the resulting document
strXMLDoc = "<?xml version="1.0"?><document><item>...</item></document>"
strXSLDoc = "<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">" _
& "<xsl:template match="/"><HTML><BODY>...</BODY></HTML>" _
& "</xsl:template></xsl:stylesheet>"
If objTransform.TransformXML(strXMLDoc, strXSLDoc, , strResult) Then
Response.Write "The transformed result is:<P>" & strResult
Else
Response.Write "An error occurred during processing<P>" & strResult
End If
Note: If you are using Internet Information Server version 4 (or higher), you may like to set the 'Run in separate memory space (isolated process)' option on the Virtual Directory page of the Properties dialog for any directories where you have pages that use the component. This also makes it possible to unload the component on demand without restarting the server.
Accepts parameters that contain: the path and name of the source XML file or a string containing a valid XML document, the path and name of the XSL style sheet file or a string containing a valid XSL stylesheet, the path and name of the disk file to write the result to (optional), and a string that will be filled with the result of the transformation or a status/error message.
The syntax of the TransformXML method is:
Success = TransformXML(XMLFile, XSLFile , [OutputFile], [ResultStatus], [ParserClassString])
The method returns a Boolean value which will be True if the transformation succeeded, or False if not. Note that the method will return True if the MSXML parser component does not report an error, even if the result is not a correctly transformed document. Also be aware that, because XSL style sheets incorporate recursion, an incorrect style sheet could cause the MSXML component to behave erratically. You may wish to verify that the transformations are correct using MSXML in Internet Explorer before creating batch update routines to use the XSLTransform component.
| Parameter | Description |
| XMLFile | Required. String. The source XML document to be transformed. The value of this parameter can be the full physical path (i.e. "c:\data\xml\myfile.xml" or "\\servername\C\xml\myfile.xml") or the virtual path (i.e. "/data/xml/myfile.xml") of a valid XML file. To use fully-qualified URLs (such as "http://domain/xml/myfile.xml") you may need to load the document using XMLHTTP first - see our support page for details. Alternatively this parameter can be a string containing a valid XML document, for example: "<?xml version='1.0'?><document><item>...</item></document>" |
| XSLFile | Optional. String. The XSL style sheet to be used to perform the transformation. The value of this parameter can be the full physical path (i.e. "c:\data\xsl\myfile.xsl" or "\\servername\C\xsl\myfile.xsl") or the virtual path (i.e. "/data/xsl/myfile.xsl")) of a valid XSL file. To use fully-qualified URLs (such as "http://domain/xsl/myfile.xsl") you may need to load the document using XMLHTTP first - see our support page for details. Alternatively it can be a string containing a valid XSL style sheet, for example: "<xsl:stylesheet xmlns:xsl='http://www.w3.org/TR/WD-xsl'><xsl:template match='/'><HTML><BODY>...</BODY></HTML></xsl:template></xsl:stylesheet>" |
| OutputFile | Optional. String. A name and (optionally) the path for a file that will be created from the results of the transformation. The value of this parameter can be the full physical path (i.e. "c:\data\results\myfile.html" or "\\servername\results\myfile.txt") or the virtual path (i.e. "/results/myfile.doc"). If this parameter is not specified (i.e. an empty string is used), the result of the transformation is returned in the ResultStatus parameter instead. |
| ResultStatus | Optional. String. If a value is provided for the OutputFile parameter, this parameter (if provided) will be set to a message indicating the success of the transformation, or an error message if the transformation fails. If a value is not provided for the OutputFile parameter, this parameter will contain the result of the transformation (i.e. the output document or result), or an error message if the transformation fails. |
| ParserClassString | Optional. String. Specifies the ProgID or class string of the XML parser component to be used to execute the transformation. The default if omitted is "MSXML.DOMDocument". To use the updated XSLT-compliant versions of the Microsoft parser specify the value "MSXML2.DOMDocument" or "MSXML2.DOMDocument.3.0" for this parameter. This parameter was added to XSLTransform in version 1.2x. See the support pages for instructions on how to upgrade to the latest version. |
Accepts parameters that contain: the path and name of a command batch file that specifies the details for multiple transformations, whether to display the progress of the operation when running in ASP (optional), and a string that will be filled with the a status/error message (optional). This method was added in version 1.10 - see the support page for details of how to obtain the latest version.
The syntax of the TransformBatch method is:
NumberOfTransformations = TransformBatch(BatchFile, [ASPVerbose], [StatusResult], [ParserClassString])
The method returns an Integer value indicating the number of transformations that succeeded, or -1 if ther was an error reading the command batch file.
| Parameter | Description |
| BatchFile | Required. String. The name and optionally the path of the command batch file. The value of this parameter can be the full physical path (i.e. "c:\data\myfile.txt" or "\\servername\C\batch\myfile.txt") or the virtual path (i.e. "/data/myfile.txt") of a command batch file stored on disk. See Command Batch File Syntax for details of the required batch file contents. |
| ASPVerbose | Optional. Boolean. If set to True, and the component is running in ASP, the progress of the operation and the result of each transformation will be displayed in the ASP page. The default if omitted is False. You can override this setting for individual transformations within the command batch file - see Command Batch File Syntax for details. |
| StatusResult | Optional. String. If this parameter is provided it will be set to a message indicating the success of the batch operation, or an error message if there is an error in the command batch file. |
| ParserClassString | Optional. String. Specifies the ProgID or class string of the XML parser component to be used to execute the transformation. The default if omitted is "MSXML.DOMDocument". To use the updated XSLT-compliant versions of the Microsoft parser specify the value "MSXML2.DOMDocument" or "MSXML2.DOMDocument.3.0" for this parameter. This parameter was added to XSLTransform in version 1.2x. See the support pages for instructions on how to upgrade to the latest version. |
This method provides a list of the names of files that are stored in a specified directory on the machine where the component is installed. You can also specify the text and HTML that is placed before and after each file name in the returned list as delimiters. The syntax of the FileListing method is:
FilesListString = FileListing(FileListRoot,
[FileSpecification],
[ListItemPrefix],
[ListItemSuffix],
[MatchesFound])
The return value is a string containing the file names, delimited with the characters specified as the ListItemPrefix and ListItemSuffix parameters. On return, the optional MatchesFound parameter contains the number of files in the list, or -1 if there was an error.
| Parameter | Description |
| FileListRoot | Required. String. Can be either the full physical path or the virtual path of the directory where the files that are to be listed reside. UNC path names starting with \\ are also permitted. |
| FileSpecification | Optional. String. A specification of files to include in the listing. Can include wildcards if required - i.e. reports*.xml or accounts.*. The default if omitted is *.* (all files). |
| ListItemPrefix | Optional. String. One or more characters that are placed before each file name in the returned file list string. Can be set to any string of characters including HTML, for example "<OPTION>" to create a list of entries for an HTML <SELECT> element. The default if omitted is an empty string. |
| ListItemSuffix | Optional. String. One or more characters that are placed after each file name in the returned file list string. Can be set to any string of characters, including HTML. The default if omitted is the string "<BR>" + Chr(13) + Chr(10) which provides a carriage return in both text and HTML formats. A simple way to handle the list is with the VBScript Split function:FileNameArray = Split(FileListString, Delimiter) |
| MatchesFound | Optional. Integer. The number of files in the returned list, or -1 if an error was encountered. |
The text batch file specified in the BatchFile parameter of the TransformBatch method should contain a series of commands that specify the individual transformations required. Each line must be terminated with a carriage return. The file can also contain blank lines and comments, and must end with a carriage return.The syntax for each command line is:
XMLFile, XSLFile, OutputFile [,Verbose]
The values for XMLFile, XSLFile and OutputFile are the same as would be specified for an individual transformation using the TransformXML method. A value for Verbose is optional, but if provided should be V or v to indicate that the progress and result information will be output for this transformation when running under ASP.
Any lines starting with ';', '#', '*' or '!' are treated as a comment line and will be ignored. An example file is:
# -------------------------------------------------------- # Example batch command file for the TransformBatch method # -------------------------------------------------------- c:\data\xml\my xml file.xml, c:\data\xsl\myfile1.xsl, c:\results\myfile1.html /data/xml/XMLFile2.xml, /data/xsl/MyXSL.xsl, /results/File2.html, V \\servername\C\data\xml\myfile3.xml, /data/xsl/myfile3.xsl, c:\results\myfile3.html, v