description | title | ms.date | dev_langs | ms.assetid | ||
---|---|---|---|---|---|---|
Learn more about: Inputs to the XslCompiledTransform Class |
Inputs to the XslCompiledTransform Class |
03/30/2017 |
|
834049f1-ab41-449e-9f10-4a1d0701bc48 |
The xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A method accepts three input types for the source document: an object that implements the xref:System.Xml.XPath.IXPathNavigable interface, an xref:System.Xml.XmlReader object that reads the source document, or a string URI.
Note
The xref:System.Xml.Xsl.XslCompiledTransform class preserves white space by default. This is in accordance with section 3.4 of the W3C XSLT 1.0 recommendation.
The xref:System.Xml.XPath.IXPathNavigable interface is implemented in the xref:System.Xml.XmlNode and xref:System.Xml.XPath.XPathDocument classes. These classes represent an in-memory cache of XML data.
-
The xref:System.Xml.XmlNode class is based on the W3C Document Object Model (DOM) and includes editing capabilities.
-
The xref:System.Xml.XPath.XPathDocument class is a read-only data store based on the XPath data model. xref:System.Xml.XPath.XPathDocument is the recommended class for XSLT processing. It provides faster performance when compared to the xref:System.Xml.XmlNode class.
Note
Transformations apply to the document as a whole. In other words, if you pass in a node other than the document root node, this does not prevent the transformation process from accessing all nodes in the loaded document. To transform a node fragment, you must create an object containing just the node fragment, and pass that object to the xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A method. For more information, see How to: Transform a Node Fragment.
The following example uses the xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A?displayProperty=nameWithType method to transform the books.xml file to the books.html file using the transform.xsl style sheet. The books.xml and transform.xsl files can be found in this topic: How to: Perform an XSLT Transformation by Using an Assembly.
[!code-csharpXslCompiledTransform.Transform2#1] [!code-vbXslCompiledTransform.Transform2#1]
The xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A method loads from the current node of the xref:System.Xml.XmlReader through all its children. This enables you to use a portion of a document as the context document. After the xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A method returns, the xref:System.Xml.XmlReader is positioned on the next node after the end of the context document. If the end of the document is reached, the xref:System.Xml.XmlReader is positioned at the end of file (EOF).
The following example uses the xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A?displayProperty=nameWithType method to transform the books.xml file to the books.html file using the transform.xsl style sheet. The books.xml and transform.xsl files can be found in this topic: How to: Perform an XSLT Transformation by Using an Assembly.
[!code-csharpXslCompiledTransform.Transform2#2] [!code-vbXslCompiledTransform.Transform2#2]
You can also specify the source document URI as your XSLT input. An xref:System.Xml.XmlResolver is used to resolve the URI. You can specify the xref:System.Xml.XmlResolver to use by passing it to the xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A method. If an xref:System.Xml.XmlResolver is not specified, the xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A method uses a default xref:System.Xml.XmlUrlResolver with no credentials.
The following example uses the xref:System.Xml.Xsl.XslCompiledTransform.Transform%2A?displayProperty=nameWithType method to transform the books.xml file to the books.html file using the transform.xsl style sheet. The books.xml and transform.xsl files can be found in this topic: How to: Perform an XSLT Transformation by Using an Assembly.
[!code-csharpXslCompiledTransform.Transform2#3] [!code-vbXslCompiledTransform.Transform2#3]
For more information, see Resolving External Resources During XSLT Processing.