XSL(T) Transformation of XML Files in NAV 2018

MattHMattH Posts: 11Member
I’m currently trying to carry-out an XML transformation an XML file that a 3rd party sends, so that is converted into a human-readable format using a supplied XSL file. This resulting file is then opened in an internet browser for subsequent printing. I’ve tried the Transformation ‘by hand’ and it works perfectly.

I’ve three filestreams (XML-in, XSL-in and XML-out). I’ve tried using the functionality (TryTransformToXMLOutstream) contained in the codeunit XML DOM Management, but it claims it can’t find the XSL file in the system32 folder, even though I have ‘given’ the process the XSL file’s data through the filestream, so I don’t know why it has gone looking for it!

I tried taking elements of the TryTransformToXMLToOutstream functionality, cross-referencing it to C# examples found on the internet, but it complained about ‘null’ parameters. I’m almost of the opinion of getting something working in .NET/C# (because it seemingly gives better flexibility for this kind of functionality) and including this as a DLL into NAV.

Anyhow, my real question: has anybody undertaken the task of Transforming an XML file using an XSL in any of their projects?


  • MaxxMaxx Posts: 6Member
    edited 2018-08-09
    Hi, xslt transformation has been made using .NET.
    Below, I've put example.

    Procedure ApplyXSLT(VAR XMLDocToApply : DotNet "System.Xml.XmlDocument";VAR XMLDoc : DotNet "System.Xml.XmlDocument")
    Name DataType Subtype Length
    StylesheetXML DotNet System.Xml.XmlDocument.'System.Xml, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    XslTransform DotNet System.Xml.Xsl.XslTransform.'System.Xml, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    XmlWriter DotNet System.IO.StringWriter.'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    nullXsltArgumentList DotNet System.Xml.Xsl.XsltArgumentList.'System.Xml, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    AppliedXMLDoc DotNet System.Xml.XmlDocument.'System.Xml, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    XslTransform := XslTransform.XslTransform;
    StylesheetXML := StylesheetXML.XmlDocument;
    StylesheetXML.InnerXml(XMLDocToApply.InnerXml); //xslt

    XmlWriter := XmlWriter.StringWriter();
    XslTransform.Transform(XMLDoc,nullXsltArgumentList,XmlWriter); // transform xmldoc wtih xslt
    AppliedXMLDoc := AppliedXMLDoc.XmlDocument;

    XMLDoc := AppliedXMLDoc; // return transformed xml doc
  • MattHMattH Posts: 11Member
    OK, thank you for the example. I shall try this as soon as I get some time on the project.
  • MattHMattH Posts: 11Member
    Thanks. This lead me toward the final (working) result.
Sign In or Register to comment.