XSL Transform example
This script library and workflow script demonstrates how to perform an XSL Transform in a Secured Mode.
This sample script uses the ReadReportFile
method to perform an XSL Transform. Instead of reading a file from disk or writing files to
disk, the process is done in-memory.
This is an example of a workflow script that uses the sample script
library:
Function wf_start() As Long
Dim xmlOrig As String = ObjectXML(_ObjectSymbol, _ObjectKey, "HEADER")
MessageList("XML Orig: ", xmlOrig)
Dim helper As New XSLTransformHelper(Me)
Dim xmlNew As String = helper.DoXSLTransform("AttributeRemove.xsl", xmlOrig)
MessageList("XML New: ", xmlNew)
Return 9111
End Function
XMLTransformHelper script library
This is the XMLTransformHelper
script library that performs
an XML Transform:
Option Strict On
Imports System
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Xsl
Public Class XSLTRANSFORMHELPER
Private co As FcProcFuncSetEvent
Public Sub New(ByRef context As FcProcFuncSetEvent)
co = context
End Sub
Public Function DoXSLTransform(ByVal XSLTFileName As String, ByVal
XMLText As String) As String
Dim xslText As String = co.ReadReportFile(XSLTFileName)
If String.IsNullOrWhiteSpace(xslText) Then
Throw New ArgumentNullException("XSLTFileName",
"DoXSLTransform missing or blank XSLT stylesheet.")
End If
Dim xslTransform As New XslCompiledTransform()
Try
Using srXSLT As New StringReader(xslText)
Using xrXSLT As XmlReader =
XmlReader.Create(srXSLT)
xslTransform.Load(xrXSLT)
End Using
End Using
Catch exXSLT As Exception
Throw New Exception("DoXSLTransform: Failed to
load XSLT stylesheet.", exXSLT)
End Try
Dim xmlOutBuilder As New StringBuilder
Try
Using swXML As New StringWriter(xmlOutBuilder)
Dim wsXML As New XmlWriterSettings()
wsXML.OmitXmlDeclaration = True
Using xwXML As XmlWriter =
XmlWriter.Create(swXML, wsXML)
Using srXML As New StringReader(XMLText)
Using xrXML As XmlReader =
XmlReader.Create(srXML)
xslTransform.Transform(xrXML, xwXML)
End Using
End Using
End Using
End Using
Catch exXSLT As Exception
Throw New Exception("DoXSLTransform: Failed to
transform.", exXSLT)
End Try
Return xmlOutBuilder.ToString()
End Function
End Class
The XSL file must be in the folder that is configured by Web.Config before the XSL Transform.