I have some deprecated XSLT scripts that include VBScript in them. They run on the old system, and I cannot change this system.
I need to make changes to XSLT in order to convert the file differently now.
I built a simple .NET project to test my XSLT transformation:
[STAThread]
public static void Main(string[] args)
{
var transform = new XslCompiledTransform(true);
transform.Load(XmlTextReaderFromEmbeddedResource("MyXSLTFile"),
new XsltSettings() { EnableDocumentFunction = true, EnableScript = true }, new XmlUrlResolver());
transform.Transform(
XmlTextReaderFromEmbeddedResource("MySourceXML"),
ToXmlTextWriter("MyOutput.xml"));
}
private static XmlTextReader XmlTextReaderFromEmbeddedResource(string resourceName)
{
var resource = typeof(Transform)
.Assembly.GetManifestResourceStream
(resourceName);
return new XmlTextReader(resource);
}
private static XmlTextWriter ToXmlTextWriter(string fileName)
{
return new XmlTextWriter(fileName, Encoding.UTF8);
}
it works, procedurally. However, XSLT scripts that are VBScript do not work well with .NET. In particular, I have a segment:
dim gRegEx
set gRegEx = New RegExp
which bombs the transformation as follows:
Type 'RegExp' is not defined.
There are many articles on how to convert this to a .NET object, but for this you need to revert to an outdated machine that will expect VBScript.
How can I write this so that it works in both environments?