XslCompiledTransform Class

XslCompiledTransform Class

 

Transforms XML data using an XSLT style sheet.

Namespace:   System.Xml.Xsl
Assembly:  System.Xml (in System.Xml.dll)

System::Object
  System.Xml.Xsl::XslCompiledTransform

public ref class XslCompiledTransform sealed 

NameDescription
System_CAPS_pubmethodXslCompiledTransform()

Initializes a new instance of the XslCompiledTransform class.

System_CAPS_pubmethodXslCompiledTransform(Boolean)

Initializes a new instance of the XslCompiledTransform class with the specified debug setting.

NameDescription
System_CAPS_pubpropertyOutputSettings

Gets an XmlWriterSettings object that contains the output information derived from the xsl:output element of the style sheet.

System_CAPS_pubpropertyTemporaryFiles

Gets the TempFileCollection that contains the temporary files generated on disk after a successful call to the Load method.

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticCompileToType(XmlReader^, XsltSettings^, XmlResolver^, Boolean, TypeBuilder^, String^)

Compiles an XSLT style sheet to a specified type.

System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodLoad(IXPathNavigable^)

Compiles the style sheet contained in the IXPathNavigable object.

System_CAPS_pubmethodLoad(IXPathNavigable^, XsltSettings^, XmlResolver^)

Compiles the XSLT style sheet contained in the IXPathNavigable. The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

System_CAPS_pubmethodLoad(MethodInfo^, array<Byte>^, array<Type^>^)

Loads a method from a style sheet compiled using the XSLTC.exe utility.

System_CAPS_pubmethodLoad(String^)

Loads and compiles the style sheet located at the specified URI.

System_CAPS_pubmethodLoad(String^, XsltSettings^, XmlResolver^)

Loads and compiles the XSLT style sheet specified by the URI. The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

System_CAPS_pubmethodLoad(Type^)

Loads the compiled style sheet that was created using the XSLT Compiler (xsltc.exe).

System_CAPS_pubmethodLoad(XmlReader^)

Compiles the style sheet contained in the XmlReader.

System_CAPS_pubmethodLoad(XmlReader^, XsltSettings^, XmlResolver^)

Compiles the XSLT style sheet contained in the XmlReader. The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodTransform(IXPathNavigable^, XmlWriter^)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter.

System_CAPS_pubmethodTransform(IXPathNavigable^, XsltArgumentList^, Stream^)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to a stream. The XsltArgumentList provides additional runtime arguments.

System_CAPS_pubmethodTransform(IXPathNavigable^, XsltArgumentList^, TextWriter^)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to an TextWriter. The XsltArgumentList provides additional run-time arguments.

System_CAPS_pubmethodTransform(IXPathNavigable^, XsltArgumentList^, XmlWriter^)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments.

System_CAPS_pubmethodTransform(IXPathNavigable^, XsltArgumentList^, XmlWriter^, XmlResolver^)

Executes the transform by using the input document that is specified by the IXPathNavigable object and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments and the XmlResolver resolves the XSLT document() function.

System_CAPS_pubmethodTransform(String^, String^)

Executes the transform using the input document specified by the URI and outputs the results to a file.

System_CAPS_pubmethodTransform(String^, XmlWriter^)

Executes the transform using the input document specified by the URI and outputs the results to an XmlWriter.

System_CAPS_pubmethodTransform(String^, XsltArgumentList^, Stream^)

Executes the transform using the input document specified by the URI and outputs the results to stream. The XsltArgumentList provides additional run-time arguments.

System_CAPS_pubmethodTransform(String^, XsltArgumentList^, TextWriter^)

Executes the transform using the input document specified by the URI and outputs the results to a TextWriter.

System_CAPS_pubmethodTransform(String^, XsltArgumentList^, XmlWriter^)

Executes the transform using the input document specified by the URI and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments.

System_CAPS_pubmethodTransform(XmlReader^, XmlWriter^)

Executes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter.

System_CAPS_pubmethodTransform(XmlReader^, XsltArgumentList^, Stream^)

Executes the transform using the input document specified by the XmlReader object and outputs the results to a stream. The XsltArgumentList provides additional run-time arguments.

System_CAPS_pubmethodTransform(XmlReader^, XsltArgumentList^, TextWriter^)

Executes the transform using the input document specified by the XmlReader object and outputs the results to a TextWriter. The XsltArgumentList provides additional run-time arguments.

System_CAPS_pubmethodTransform(XmlReader^, XsltArgumentList^, XmlWriter^)

Executes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments.

System_CAPS_pubmethodTransform(XmlReader^, XsltArgumentList^, XmlWriter^, XmlResolver^)

Executes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments and the XmlResolver resolves the XSLT document() function.

The XslCompiledTransform class is an XSLT processor that supports the XSLT 1.0 syntax. It is a new implementation and includes performance gains when compared to the obsolete XslTransform class. The structure of the XslCompiledTransform class is very similar to the XslTransform class. The Load method loads and compiles the style sheet, while the Transform method executes the XSLT transform.

Support for the XSLT document() function and embedded script blocks are disabled by default. These features can be enabled by creating an XsltSettings object and passing it to the Load method.

For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

When creating an application that uses the XslCompiledTransform class, you should be aware of the following items and their implications:

  • XSLT scripting is disabled by default. XSLT scripting should be enabled only if you require script support and you are working in a fully trusted environment.

  • The XSLT document() function is disabled by default. If you enable the document() function, restrict the resources that can be accessed by passing an XmlSecureResolver object to the Transform method.

  • Extension objects are enabled by default. If an XsltArgumentList object containing extension objects is passed to the Transform method, they are utilized.

  • XSLT style sheets can include references to other files and embedded script blocks. A malicious user can exploit this by supplying you with data or style sheets that when executed can cause your system to process until the computer runs low on resources.

  • XSLT applications that run in a mixed trust environment can result in style sheet spoofing. For example, a malicious user can load an object with a harmful style sheet and hand it off to another user who subsequently calls the Transform method and executes the transformation.

These security issues can be mitigated by not enabling scripting or the document() function unless the style sheet comes from a trusted source, and by not accepting XslCompiledTransform objects, XSLT style sheets, or XML source data from an untrusted source.

The following example executes a transform and outputs to a file.

No code example is currently available or this language may not be supported.

The sample uses the following two input files:

books.xml

<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore>
  <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography of Benjamin Franklin</title>
    <author>
      <first-name>Benjamin</first-name>
      <last-name>Franklin</last-name>
    </author>
    <price>8.99</price>
  </book>
  <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
    <title>The Confidence Man</title>
    <author>
      <first-name>Herman</first-name>
      <last-name>Melville</last-name>
    </author>
    <price>11.99</price>
  </book>
  <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

output.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="bookstore">
  <HTML>
    <BODY>
      <TABLE BORDER="2">
        <TR>
          <TD>ISBN</TD>
          <TD>Title</TD>
          <TD>Price</TD>
        </TR>
        <xsl:apply-templates select="book"/>
      </TABLE>
    </BODY>
  </HTML>
</xsl:template>
<xsl:template match="book">
  <TR>
    <TD><xsl:value-of select="@ISBN"/></TD>
    <TD><xsl:value-of select="title"/></TD>
    <TD><xsl:value-of select="price"/></TD>
  </TR>
</xsl:template>
</xsl:stylesheet>

.NET Framework
Available since 2.0

The XslCompiledTransform object is thread safe once it has been loaded. In other words, after the Load method has successfully completed, the Transform method can be called simultaneously from multiple threads.

If the Load method is called again in one thread while the Transform method is being called in another thread, the XslCompiledTransform object finishes executing the Transform call by continuing to use the old state. The new state is used when the Load method successfully completes.

System_CAPS_noteNote

The Load method is not thread safe when called simultaneously from multiple threads.

Return to top
Show:
© 2016 Microsoft