Differences between revisions 1 and 2
Revision 1 as of 2008-06-20 13:21:03
Size: 1817
Comment: First draft
Revision 2 as of 2008-06-20 13:26:42
Size: 1881
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Applying and XSLT transformation = = Applying an XSLT transformation =
Line 18: Line 18:
.Net 2.0 replaced the {{{XslTransform}}} class with {{{[:http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx:XslCompiledTransform]}}}, making {{{XslTransform}}} obsolete.
Line 20: Line 19:
{{{XslCompiledTransform}}} is faster than its predecessor and also closes some [:http://msdn.microsoft.com/en-us/library/ms172414.aspx:security] loopholes in its predecessor, which should be avoided. == XslCompiledTransform replaces XslTransform ==

.Net 2.0 replaced the {{{XslTransform}}} class with {{{XslCompiledTransform}}} ([http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx MSDN article]), making {{{XslTransform}}} obsolete.

{{{XslCompiledTransform}}} is faster than its predecessor and also closes some [http://msdn.microsoft.com/en-us/library/ms172414.aspx security] loopholes in its predecessor, which should be avoided.
Line 25: Line 28:
This second example deals with an XSL stylesheet that contains a short [:http://en.wikipedia.org/wiki/Document_Type_Definition:DTD] section declaring an entity. Because the stylesheet comes from a trusted source we want the stylesheet processor to accept it. (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.) This is a common situation when processing your own XML files; for example, in converting [:http://www.docbook.org:DocBook] source into either web pages or camera-ready PDF files. So this otherwise minimal example extends to permitting DTD processing. This second example deals with an XSL stylesheet that contains a short [http://en.wikipedia.org/wiki/Document_Type_Definition DTD] section declaring an entity. Because the stylesheet comes from a trusted source we want the stylesheet processor to accept it. (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.) This is a common situation when processing your own XML files; for example, in converting [http://www.docbook.org DocBook] source into either web pages or camera-ready PDF files. So this otherwise minimal example extends to permitting DTD processing.

Applying an XSLT transformation

Simple case

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

      +⎕USING←'System' 'System.Xml,System.Xml.dll' 'System.Xml.Xsl,System.Xml.dll'
 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 ([http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx MSDN article]), making XslTransform obsolete.

XslCompiledTransform is faster than its predecessor and also closes some [http://msdn.microsoft.com/en-us/library/ms172414.aspx security] loopholes in its predecessor, which should be avoided.

Processing Document Type Definitions

This second example deals with an XSL stylesheet that contains a short [http://en.wikipedia.org/wiki/Document_Type_Definition DTD] section declaring an entity. Because the stylesheet comes from a trusted source we want the stylesheet processor to accept it. (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.) This is a common situation when processing your own XML files; for example, in converting [http://www.docbook.org DocBook] source into either web pages or camera-ready PDF files. So this otherwise minimal example extends to permitting DTD processing.

      xrs←⎕NEW XmlReaderSettings
      xrs.ProhibitDtd←0

      rdr←XmlReader.Create XSL xrs

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

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