Applying an XSLT transformation

Simple case

      SRC←'C:\Temp\source.xml'
      TGT←'C:\Temp\target.txt'
      XSL←'C:\Temp\stylesheet.xsl'

      ⎕USING←'System' 'System.Xml,System.Xml.dll' 'System.Xml.Xsl,System.Xml.dll'

      xslt←⎕NEW XslCompiledTransform
      xslt.Load⊂XSL
      xslt.Transform SRC TGT

XslCompiledTransform replaces XslTransform

.Net 2.0 replaced the XslTransform class with XslCompiledTransform (MSDN article), making XslTransform obsolete.

XslCompiledTransform is faster than its predecessor and also closes some security loopholes in its predecessor, which should be avoided.

Processing Document Type Definitions

The simple example above will not process the files attached to this article. The stylesheet processor rejects the forecast.xsl stylesheet, because it contains a short DTD section declaring an entity.

Accepting the DTD gives the stylesheet processor a bit a of a blank cheque. Entity declarations can be used to include other files. So the processor is prohibited from processing DTD by default. But this stylesheet comes from a trusted source and we want the stylesheet processor to accept it.

This is a common situation when processing your own XML files; for example, in converting DocBook source into either web pages or camera-ready PDF files. So this otherwise minimal example extends to permitting DTD processing.

      SRC←'C:\Temp\forecasts2008.xml'
      TGT←'C:\Temp\forecasts.inc'
      XSL←'C:\Temp\forecasts.xsl'

      xrs←⎕NEW XmlReaderSettings
      xrs.ProhibitDtd←0

      rdr←XmlReader.Create XSL xrs

      xslt←⎕NEW XslCompiledTransform
      xslt.Load rdr
      xslt.Transform SRC TGT

Author: StephenTaylor

There are 3 attachment(s) stored for this page.


CategoryDotNet - CategoryDyalogDotNet - CategoryDyalogExamplesDotNet

XsltTransform (last edited 2015-04-05 01:30:14 by PierreGilbert)