I have some legacy XSLT scripts that incorporate VBScript in them. They are run on an old system and I can't change that system.
I am required to make a change to an XSLT to transform a file differently now.
I built a simple .NET project to test my XSLT transform:
[STAThread]
public static void Main(string[] args)
{
var transform = new XslCompiledTransform(true);
//foreach (var file in System.Reflection.Assembly
// .GetExecutingAssembly().GetManifestResourceNames()
// )
//{
// Console.WriteLine(file);
//}
//Console.ReadKey();
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);
}
this works, procedurally. However, the scripts in the XSLT, being VBScript, aren't playing well with .NET. Specifically, I have a segment:
dim gRegEx
set gRegEx = New RegExp
which bombs the transform as:
Type 'RegExp' is not defined.
There's lots of articles about how to convert this to a .NET object, but this needs to go back to a legacy machine that will be expecting VBScript.
How can I write this so that it will work in both environments?