XslCompiledTransform.Load Método

Definição

Compila a folha de estilos.Compiles the style sheet.

Sobrecargas

Load(IXPathNavigable, XsltSettings, XmlResolver)

Compila a folha de estilos XSLT contida no IXPathNavigable.Compiles the XSLT style sheet contained in the IXPathNavigable. O XmlResolver resolve qualquer elemento XSLT import e include e as configurações de XSLT determinam as permissões para a folha de estilos.The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

Load(String, XsltSettings, XmlResolver)

Carrega e compila a folha de estilos XSLT especificada pelo URI.Loads and compiles the XSLT style sheet specified by the URI. O XmlResolver resolve qualquer elemento XSLT import e include e as configurações de XSLT determinam as permissões para a folha de estilos.The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

Load(MethodInfo, Byte[], Type[])

Carrega um método de uma folha de estilos compilada usando o utilitário XSLTC.exe.Loads a method from a style sheet compiled using the XSLTC.exe utility.

Load(XmlReader, XsltSettings, XmlResolver)

Compila a folha de estilos XSLT contida no XmlReader.Compiles the XSLT style sheet contained in the XmlReader. O XmlResolver resolve qualquer elemento XSLT import e include e as configurações de XSLT determinam as permissões para a folha de estilos.The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

Load(XmlReader)

Compila a folha de estilos contida no XmlReader.Compiles the style sheet contained in the XmlReader.

Load(Type)

Carrega a folha de estilos compilada que foi criada usando o Compilador de XSLT (xsltc.exe).Loads the compiled style sheet that was created using the XSLT Compiler (xsltc.exe).

Load(String)

Carrega e compila a folha de estilos localizada no URI especificado.Loads and compiles the style sheet located at the specified URI.

Load(IXPathNavigable)

Compila a folha de estilos contida no objeto IXPathNavigable.Compiles the style sheet contained in the IXPathNavigable object.

Comentários

Embora o desempenho geral da classe XslCompiledTransform seja melhor do que o da classe XslTransform, o método Load da classe XslCompiledTransform possivelmente apresentará um desempenho mais lento do que o método Load da classe XslTransform na primeira vez que for chamado em uma transformação.Although the overall performance of the XslCompiledTransform class is better than the XslTransform class, the Load method of the XslCompiledTransform class might perform more slowly than the Load method of the XslTransform class the first time it is called on a transformation. Isso ocorre porque o arquivo XSLT deve ser compilado antes que seja carregado.This is because the XSLT file must be compiled before it is loaded. Para saber mais, confira a postagem de blog a seguir: XslCompiledTransform mais lento do que XslTransform?For more information, see the following blog post: XslCompiledTransform Slower than XslTransform?

Observação

Existem diferenças entre XSLT compilou no modo de depuração e em XSLT compilados no modo de versão.There are differences between XSLT compiled in Debug mode and XSLT compiled in Release mode. Em algumas situações, folhas de estilos compiladas no modo de depuração não) lançarão erros durante Load, mas irão falhar mais tarde durante Transform.In some situations, style sheets compiled in Debug mode will not throw errors during Load, but will later fail during Transform. A mesma folha de estilo embutido no modo de lançamento falhará durante Load.The same style sheet compiled in Release mode will fail during Load. Um exemplo desse comportamento é quando uma variável que não seja de um tipo nó- definido é atribuído a uma expressão onde nó- definido é necessário.An example of such behavior is when a variable that is not of a node-set type is assigned to an expression where a node-set is required.

Load(IXPathNavigable, XsltSettings, XmlResolver)

Compila a folha de estilos XSLT contida no IXPathNavigable.Compiles the XSLT style sheet contained in the IXPathNavigable. O XmlResolver resolve qualquer elemento XSLT import e include e as configurações de XSLT determinam as permissões para a folha de estilos.The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

public:
 void Load(System::Xml::XPath::IXPathNavigable ^ stylesheet, System::Xml::Xsl::XsltSettings ^ settings, System::Xml::XmlResolver ^ stylesheetResolver);
public void Load (System.Xml.XPath.IXPathNavigable stylesheet, System.Xml.Xsl.XsltSettings settings, System.Xml.XmlResolver stylesheetResolver);
member this.Load : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltSettings * System.Xml.XmlResolver -> unit
Public Sub Load (stylesheet As IXPathNavigable, settings As XsltSettings, stylesheetResolver As XmlResolver)

Parâmetros

stylesheet
IXPathNavigable

Um objeto implementando a interface IXPathNavigable.An object implementing the IXPathNavigable interface. No Microsoft .NET Framework, isso pode ser um XmlNode (normalmente, um XmlDocument) ou um XPathDocument que contém a folha de estilos.In the Microsoft .NET Framework, this can be either an XmlNode (typically an XmlDocument), or an XPathDocument containing the style sheet.

settings
XsltSettings

O XsltSettings a ser aplicado à folha de estilos.The XsltSettings to apply to the style sheet. Se isso for null, a configuração Default será aplicada.If this is null, the Default setting is applied.

stylesheetResolver
XmlResolver

O XmlResolver usado para resolver as folhas de estilos referenciadas nos elementos XSLT import e include.The XmlResolver used to resolve any style sheets referenced in XSLT import and include elements. Se for null, os recursos externos não serão resolvidos.If this is null, external resources are not resolved.

Exceções

O valor stylesheet é null.The stylesheet value is null.

A folha de estilos contém um erro.The style sheet contains an error.

Exemplos

O exemplo a seguir carrega uma folha de estilos.The following example loads a style sheet. O XmlSecureResolver objeto contém as credenciais necessárias para acessar qualquer import elemento include ou encontrado na folha de estilos.The XmlSecureResolver object contains the credentials necessary to access any import or include elements found in the style sheet.

// Create a resolver and specify the necessary credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
System.Net.NetworkCredential myCred;
myCred  = new System.Net.NetworkCredential(UserName,SecurelyStoredPassword,Domain);  
resolver.Credentials = myCred;
  
// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(new XPathDocument("http://serverName/data/xsl/sort.xsl"), XsltSettings.Default, resolver);
' Create a resolver and specify the necessary credentials.
Dim resolver As New XmlUrlResolver()
Dim myCred As System.Net.NetworkCredential
myCred = New System.Net.NetworkCredential(UserName, SecurelyStoredPassword, Domain)
resolver.Credentials = myCred
        
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load(New XPathDocument("http://serverName/data/xsl/sort.xsl"), XsltSettings.Default, resolver)

Comentários

A XslCompiledTransform classe dá suporte à sintaxe XSLT 1,0.The XslCompiledTransform class supports the XSLT 1.0 syntax. A folha de estilos XSLT deve usar http://www.w3.org/1999/XSL/Transform o namespace.The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

Veja também

Load(String, XsltSettings, XmlResolver)

Carrega e compila a folha de estilos XSLT especificada pelo URI.Loads and compiles the XSLT style sheet specified by the URI. O XmlResolver resolve qualquer elemento XSLT import e include e as configurações de XSLT determinam as permissões para a folha de estilos.The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

public:
 void Load(System::String ^ stylesheetUri, System::Xml::Xsl::XsltSettings ^ settings, System::Xml::XmlResolver ^ stylesheetResolver);
public void Load (string stylesheetUri, System.Xml.Xsl.XsltSettings settings, System.Xml.XmlResolver stylesheetResolver);
member this.Load : string * System.Xml.Xsl.XsltSettings * System.Xml.XmlResolver -> unit
Public Sub Load (stylesheetUri As String, settings As XsltSettings, stylesheetResolver As XmlResolver)

Parâmetros

stylesheetUri
String

O URI da folha de estilos.The URI of the style sheet.

settings
XsltSettings

O XsltSettings a ser aplicado à folha de estilos.The XsltSettings to apply to the style sheet. Se isso for null, a configuração Default será aplicada.If this is null, the Default setting is applied.

stylesheetResolver
XmlResolver

O XmlResolver usado para resolver o URI de folha de estilos e quaisquer folhas de estilos referenciadas nos elementos XSLT import e include.The XmlResolver used to resolve the style sheet URI and any style sheets referenced in XSLT import and include elements.

Exceções

O valor stylesheetUri ou stylesheetResolver é null.The stylesheetUri or stylesheetResolver value is null.

A folha de estilos contém um erro.The style sheet contains an error.

A folha de estilos não foi encontrada.The style sheet cannot be found.

O valor stylesheetUri inclui um nome de arquivo ou diretório que não pôde ser encontrado.The stylesheetUri value includes a filename or directory that cannot be found.

Não é possível resolver um valor stylesheetUri.The stylesheetUri value cannot be resolved.

- ou --or- Ocorreu um erro ao processar a solicitação.An error occurred while processing the request.

stylesheetUri não é um URI válido.stylesheetUri is not a valid URI.

Ocorreu um erro de análise ao carregar a folha de estilos.There was a parsing error loading the style sheet.

Exemplos

O exemplo a seguir carrega uma folha de estilos que é armazenada em um recurso de rede.The following example loads a style sheet that is stored on a network resource. Um objeto de XmlSecureResolver especifica as credenciais necessárias para acessar a folha de estilos.An XmlSecureResolver object specifies the credentials necessary to access the style sheet.

// Create the XslCompiledTransform object.
XslCompiledTransform xslt = new XslCompiledTransform();

// Create a resolver and set the credentials to use.
XmlSecureResolver resolver = new XmlSecureResolver(new XmlUrlResolver(), "http://serverName/data/");
resolver.Credentials = CredentialCache.DefaultCredentials;
  
// Load the style sheet.
xslt.Load("http://serverName/data/xsl/sort.xsl", null, resolver);
' Create the XslCompiledTransform object.
Dim xslt As New XslCompiledTransform()
        
' Create a resolver and set the credentials to use.
Dim resolver As New XmlSecureResolver(New XmlUrlResolver(), "http://serverName/data/")
resolver.Credentials = CredentialCache.DefaultCredentials
        
' Load the style sheet.
xslt.Load("http://serverName/data/xsl/sort.xsl", Nothing, resolver)

Comentários

A XslCompiledTransform classe dá suporte à sintaxe XSLT 1,0.The XslCompiledTransform class supports the XSLT 1.0 syntax. A folha de estilos XSLT deve usar http://www.w3.org/1999/XSL/Transform o namespace.The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

Um XmlReader com configurações padrão é usado para carregar a folha de estilos.An XmlReader with default settings is used to load the style sheet. O processamento de XmlReaderDTD está desabilitado no.DTD processing is disabled on the XmlReader. Se você precisar de processamento de DTD, XmlReader crie um com esse recurso habilitado e passe-o Load para o método.If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Load method.

Veja também

Load(MethodInfo, Byte[], Type[])

Carrega um método de uma folha de estilos compilada usando o utilitário XSLTC.exe.Loads a method from a style sheet compiled using the XSLTC.exe utility.

public:
 void Load(System::Reflection::MethodInfo ^ executeMethod, cli::array <System::Byte> ^ queryData, cli::array <Type ^> ^ earlyBoundTypes);
public void Load (System.Reflection.MethodInfo executeMethod, byte[] queryData, Type[] earlyBoundTypes);
member this.Load : System.Reflection.MethodInfo * byte[] * Type[] -> unit
Public Sub Load (executeMethod As MethodInfo, queryData As Byte(), earlyBoundTypes As Type())

Parâmetros

executeMethod
MethodInfo

Um objeto MethodInfo que representa o método execute gerado pelo compilador da folha de estilos compilada.A MethodInfo object representing the compiler-generated execute method of the compiled style sheet.

queryData
Byte[]

Uma matriz de bytes de estruturas de dados serializados no campo staticData da folha de estilos compilada, como gerada pelo método CompileToType(XmlReader, XsltSettings, XmlResolver, Boolean, TypeBuilder, String).A byte array of serialized data structures in the staticData field of the compiled style sheet as generated by the CompileToType(XmlReader, XsltSettings, XmlResolver, Boolean, TypeBuilder, String) method.

earlyBoundTypes
Type[]

Uma matriz de tipos armazenada no campo ebTypes gerado pelo compilador da folha de estilos compilada.An array of types stored in the compiler-generated ebTypes field of the compiled style sheet.

Exemplos

O exemplo de código a seguir Load usa o para carregar uma folha de estilos compilada.The code example below uses the Load to load a compiled style sheet. A transformação reduz o valor do Price elemento em dez por cento.The transformation reduces the value of the Price element by ten percent.

using System;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Xsl;

class Example
{
    static void Main()
    {
        // Load a stylesheet compiled using the XSLTC.EXE utility
        Type compiledStylesheet = Assembly.Load("Transform").GetType("Transform");

        // Extract private members from the compiled stylesheet
        BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Static;
        MethodInfo executeMethod = compiledStylesheet.GetMethod("Execute", bindingFlags);
        object staticData = compiledStylesheet.GetField("staticData", bindingFlags).GetValue(null);
        object earlyBoundTypes = compiledStylesheet.GetField("ebTypes", bindingFlags).GetValue(null);

        // Load into XslCompiledTransform
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load(executeMethod, (byte[])staticData, (Type[])earlyBoundTypes);

        // Run the transformation
        xslt.Transform(XmlReader.Create(new StringReader("<Root><Price>9.50</Price></Root>")), (XsltArgumentList)null, Console.Out);
    }
}
Imports System.IO
Imports System.Reflection
Imports System.Xml
Imports System.Xml.Xsl

Module Module1

    Sub Main()
        ' Load a stylesheet compiled using the XSLTC.EXE utility
        Dim compiledStylesheet As Type = [Assembly].Load("Transform").GetType("Transform")

        ' Extract private members from the compiled stylesheet
        Dim bindingFlags As BindingFlags = bindingFlags.NonPublic Or bindingFlags.Static
        Dim executeMethod As MethodInfo = compiledStylesheet.GetMethod("Execute", bindingFlags)
        Dim staticData As Object = compiledStylesheet.GetField("staticData", bindingFlags).GetValue(Nothing)
        Dim earlyBoundTypes As Object = compiledStylesheet.GetField("ebTypes", bindingFlags).GetValue(Nothing)

        ' Load into XslCompiledTransform
        Dim xslt As New XslCompiledTransform()
        xslt.Load(executeMethod, CType(staticData, Byte()), CType(earlyBoundTypes, Type()))

        ' Run the transformation
        xslt.Transform(XmlReader.Create(New StringReader("<Root><Price>9.50</Price></Root>")), CType(Nothing, XsltArgumentList), Console.Out)
    End Sub
End Module

Observação

O assembly "Transform" usado neste exemplo foi criado usando o utilitário xsltc. exe.The "Transform" assembly used in this example was built using the xsltc.exe utility. Para obter informações detalhadas sobre como usar essa ferramenta de linha de comando, consulte Como: Execute uma Transformação XSLT usando um Assembly.For detailed information on using this command line tool, see How to: Perform an XSLT Transformation by Using an Assembly.

O exemplo de código anterior usa a seguinte transformação:The previous code example uses the following transformation:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:user="urn:my-scripts">
  <msxsl:script language="C#" implements-prefix="user">
    <![CDATA[
  public double modifyPrice(double price){
    price*=0.9;
    return price;
  }
  ]]>
  </msxsl:script>
  <xsl:template match="Root">
    <Root xmlns="">
      <Price><xsl:value-of select="user:modifyPrice(Price)"/></Price>
    </Root>
  </xsl:template>
</xsl:stylesheet>

Comentários

Esse método aceita uma folha de estilos compilada na forma de MethodInfo um objeto, uma matriz de bytes e uma matriz de tipos.This method accepts a compiled style sheet in the form of a MethodInfo object, a byte array, and a type array. DynamicMethodos objetos podem ser usados para permitir que os métodos de folha de estilo compilados sejam XslCompiledTransform descartados quando o objeto for recuperado.DynamicMethod objects may be used to allow compiled style sheet methods to be discarded when the XslCompiledTransform object is reclaimed.

Load(XmlReader, XsltSettings, XmlResolver)

Compila a folha de estilos XSLT contida no XmlReader.Compiles the XSLT style sheet contained in the XmlReader. O XmlResolver resolve qualquer elemento XSLT import e include e as configurações de XSLT determinam as permissões para a folha de estilos.The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

public:
 void Load(System::Xml::XmlReader ^ stylesheet, System::Xml::Xsl::XsltSettings ^ settings, System::Xml::XmlResolver ^ stylesheetResolver);
public void Load (System.Xml.XmlReader stylesheet, System.Xml.Xsl.XsltSettings settings, System.Xml.XmlResolver stylesheetResolver);
member this.Load : System.Xml.XmlReader * System.Xml.Xsl.XsltSettings * System.Xml.XmlResolver -> unit
Public Sub Load (stylesheet As XmlReader, settings As XsltSettings, stylesheetResolver As XmlResolver)

Parâmetros

stylesheet
XmlReader

O XmlReader que contém a folha de estilos.The XmlReader containing the style sheet.

settings
XsltSettings

O XsltSettings a ser aplicado à folha de estilos.The XsltSettings to apply to the style sheet. Se isso for null, a configuração Default será aplicada.If this is null, the Default setting is applied.

stylesheetResolver
XmlResolver

O XmlResolver usado para resolver as folhas de estilos referenciadas nos elementos XSLT import e include.The XmlResolver used to resolve any style sheets referenced in XSLT import and include elements. Se for null, os recursos externos não serão resolvidos.If this is null, external resources are not resolved.

Exceções

O valor stylesheet é null.The stylesheet value is null.

A folha de estilos contém um erro.The style sheet contains an error.

Exemplos

O exemplo a seguir carrega uma folha de estilo e habilita o suporte para script XSLT.The following example loads a style sheet and enables support for XSLT scripting.

// Create the XslCompiledTransform object.
XslCompiledTransform xslt = new XslCompiledTransform();

// Create a resolver and set the credentials to use.
XmlSecureResolver resolver = new XmlSecureResolver(new XmlUrlResolver(), "http://serverName/data/");
resolver.Credentials = CredentialCache.DefaultCredentials;
  
XmlReader reader = XmlReader.Create("http://serverName/data/xsl/sort.xsl");

// Create the XsltSettings object with script enabled.
XsltSettings settings = new XsltSettings(false,true);

// Load the style sheet.
xslt.Load(reader, settings, resolver);
' Create the XslCompiledTransform object.
Dim xslt As New XslCompiledTransform()
        
' Create a resolver and set the credentials to use.
Dim resolver As New XmlSecureResolver(New XmlUrlResolver(), "http://serverName/data/")
resolver.Credentials = CredentialCache.DefaultCredentials
        
Dim reader As XmlReader = XmlReader.Create("http://serverName/data/xsl/sort.xsl")
        
' Create the XsltSettings object with script enabled.
Dim settings As New XsltSettings(False, True)
        
' Load the style sheet.
xslt.Load(reader, settings, resolver)

Comentários

A XslCompiledTransform classe dá suporte à sintaxe XSLT 1,0.The XslCompiledTransform class supports the XSLT 1.0 syntax. A folha de estilos XSLT deve usar http://www.w3.org/1999/XSL/Transform o namespace.The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

A folha de estilos é carregada do nó atual do XmlReader através de todos os seus filhos.The style sheet loads from the current node of the XmlReader through all its children. Isso permite que você use uma parte de um documento como folha de estilos.This enables you to use a portion of a document as the style sheet. Depois que Load o método for concluído, XmlReader o será posicionado no próximo nó após o final da folha de estilos.After the Load method completes, the XmlReader is positioned on the next node after the end of the style sheet. Se o final do documento é alcançada, XmlReader está localizado no final do arquivo (EOF).If the end of the document is reached, the XmlReader is positioned at the end of file (EOF).

Veja também

Load(XmlReader)

Compila a folha de estilos contida no XmlReader.Compiles the style sheet contained in the XmlReader.

public:
 void Load(System::Xml::XmlReader ^ stylesheet);
public void Load (System.Xml.XmlReader stylesheet);
member this.Load : System.Xml.XmlReader -> unit
Public Sub Load (stylesheet As XmlReader)

Parâmetros

stylesheet
XmlReader

Um XmlReader que contém a folha de estilos.An XmlReader containing the style sheet.

Exceções

O valor stylesheet é null.The stylesheet value is null.

A folha de estilos contém um erro.The style sheet contains an error.

Exemplos

O exemplo a seguir carrega uma folha de estilos contida XmlReader em um objeto.The following example loads a style sheet contained in an XmlReader object.

// Create a reader that contains the style sheet.
XmlReader reader = XmlReader.Create("titles.xsl");
reader.ReadToDescendant("xsl:stylesheet");

// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(reader);
' Create a reader that contains the style sheet.
Dim reader As XmlReader = XmlReader.Create("titles.xsl")
reader.ReadToDescendant("xsl:stylesheet")
        
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load(reader)

Comentários

A XslCompiledTransform classe dá suporte à sintaxe XSLT 1,0.The XslCompiledTransform class supports the XSLT 1.0 syntax. A folha de estilos XSLT deve usar http://www.w3.org/1999/XSL/Transform o namespace.The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

A folha de estilos é carregada do nó atual do XmlReader através de todos os seus filhos.The style sheet loads from the current node of the XmlReader through all its children. Isso permite que você use uma parte de um documento como folha de estilos.This enables you to use a portion of a document as the style sheet. Depois que Load o método for concluído, XmlReader o será posicionado no próximo nó após o final da folha de estilos.After the Load method completes, the XmlReader is positioned on the next node after the end of the style sheet. Se o final do documento é alcançada, XmlReader está localizado no final do arquivo (EOF).If the end of the document is reached, the XmlReader is positioned at the end of file (EOF).

Esse método tem o seguinte comportamento:This method has the following behavior:

  • Um XmlUrlResolver sem credenciais de usuário é usado para processar qualquer xsl:import elemento xsl:include ou.An XmlUrlResolver with no user credentials is used to process any xsl:import or xsl:include elements.

  • A document() função está desabilitada.The document() function is disabled.

  • Não há suporte para scripts inseridos.Embedded scripts are not supported.

Você pode usar a Load(XmlReader, XsltSettings, XmlResolver) sobrecarga para especificar um XmlResolver com as credenciais de autenticação necessárias ou para especificar diferentes configurações de XSLT.You can use the Load(XmlReader, XsltSettings, XmlResolver) overload to specify an XmlResolver with the necessary authentication credentials, or to specify different XSLT settings.

Veja também

Load(Type)

Carrega a folha de estilos compilada que foi criada usando o Compilador de XSLT (xsltc.exe).Loads the compiled style sheet that was created using the XSLT Compiler (xsltc.exe).

public:
 void Load(Type ^ compiledStylesheet);
public void Load (Type compiledStylesheet);
member this.Load : Type -> unit
Public Sub Load (compiledStylesheet As Type)

Parâmetros

compiledStylesheet
Type

O nome da classe que contém a folha de estilos compilada.The name of the class that contains the compiled style sheet.

Esse geralmente é o nome da folha de estilos.This is usually the name of the style sheet. A menos que especificado de outra forma, a ferramenta xsltc.exe usa o nome da folha de estilos para os nomes de classe e de assembly.Unless otherwise specified, the xsltc.exe tool uses the name of the style sheet for the class and assembly names.

Exemplos

O exemplo a seguir mostra como carregar uma folha de estilos compilada de um assembly XSLT.The following example shows how to load a compiled style sheet from an XSLT assembly. O exemplo supõe que a ferramenta xsltc. exe foi usada para criar um assembly chamado bookOrders. dll com uma classe chamada bookOrders.The example assumes that the xsltc.exe tool was used to create an assembly named bookOrders.dll with a class named bookOrders.

Observação

Você precisa referenciar o assembly XSLT ao compilar o código.You have to reference the XSLT assembly when compiling the code. Por exemplo, csc /r:system.dll;system.xml.dll;bookOrders.dll myCode.cs.For example, csc /r:system.dll;system.xml.dll;bookOrders.dll myCode.cs.

// Load the type of the class.  
XslCompiledTransform xslt = new XslCompiledTransform();  
xslt.Load(typeof(bookOrders));  

Comentários

A ferramenta xsltc. exe é usada para compilar folhas de estilo e gerar assemblies a partir das folhas de estilo.The xsltc.exe tool is used to compile style sheets and generate assemblies from the style sheets. O Load método carrega a folha de estilos compilada do assembly.The Load method loads the compiled style sheet from the assembly.

Observação

Você também deve incluir o assembly XSLT como uma referência em seu aplicativo.You must also include the XSLT assembly as a reference in your application.

Veja também

Load(String)

Carrega e compila a folha de estilos localizada no URI especificado.Loads and compiles the style sheet located at the specified URI.

public:
 void Load(System::String ^ stylesheetUri);
public void Load (string stylesheetUri);
member this.Load : string -> unit
Public Sub Load (stylesheetUri As String)

Parâmetros

stylesheetUri
String

O URI da folha de estilos.The URI of the style sheet.

Exceções

O valor stylesheetUri é null.The stylesheetUri value is null.

A folha de estilos contém um erro.The style sheet contains an error.

A folha de estilos não foi encontrada.The style sheet cannot be found.

O valor stylesheetUri inclui um nome de arquivo ou diretório que não pôde ser encontrado.The stylesheetUri value includes a filename or directory that cannot be found.

Não é possível resolver um valor stylesheetUri.The stylesheetUri value cannot be resolved.

- ou --or- Ocorreu um erro ao processar a solicitação.An error occurred while processing the request.

stylesheetUri não é um URI válido.stylesheetUri is not a valid URI.

Ocorreu um erro de análise ao carregar a folha de estilos.There was a parsing error loading the style sheet.

Exemplos

O exemplo a seguir executa uma transformação e saídas para um arquivo.The following example executes a transform and outputs to a file.

// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("output.xsl");

// Execute the transform and output the results to a file.
xslt.Transform("books.xml", "books.html");
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Execute the transform and output the results to a file.
xslt.Transform("books.xml", "books.html")

Comentários

A XslCompiledTransform classe dá suporte à sintaxe XSLT 1,0.The XslCompiledTransform class supports the XSLT 1.0 syntax. A folha de estilos XSLT deve usar http://www.w3.org/1999/XSL/Transform o namespace.The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

Esse método tem o seguinte comportamento:This method has the following behavior:

  • Um XmlUrlResolver sem credenciais de usuário é usado para resolver o URI da folha de estilo e processar xsl:import qualquer xsl:include elemento ou.An XmlUrlResolver with no user credentials is used to resolve the style sheet URI, and process any xsl:import or xsl:include elements.

  • Um XmlReader com configurações padrão é usado para carregar a folha de estilos.An XmlReader with default settings is used to load the style sheet. O processamento de XmlReaderDTD está desabilitado no.DTD processing is disabled on the XmlReader. Se você precisar de processamento de DTD, XmlReader crie um com esse recurso habilitado e passe-o Load para o método.If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Load method.

  • A document() função está desabilitada.The document() function is disabled.

  • Não há suporte para scripts inseridos.Embedded scripts are not supported.

Você pode usar a Load(String, XsltSettings, XmlResolver) sobrecarga para especificar um XmlResolver com as credenciais de autenticação necessárias ou para especificar diferentes configurações de XSLT.You can use the Load(String, XsltSettings, XmlResolver) overload to specify an XmlResolver with the necessary authentication credentials, or to specify different XSLT settings.

Veja também

Load(IXPathNavigable)

Compila a folha de estilos contida no objeto IXPathNavigable.Compiles the style sheet contained in the IXPathNavigable object.

public:
 void Load(System::Xml::XPath::IXPathNavigable ^ stylesheet);
public void Load (System.Xml.XPath.IXPathNavigable stylesheet);
member this.Load : System.Xml.XPath.IXPathNavigable -> unit
Public Sub Load (stylesheet As IXPathNavigable)

Parâmetros

stylesheet
IXPathNavigable

Um objeto implementando a interface IXPathNavigable.An object implementing the IXPathNavigable interface. No Microsoft .NET Framework, isso pode ser um XmlNode (normalmente, um XmlDocument) ou um XPathDocument que contém a folha de estilos.In the Microsoft .NET Framework, this can be either an XmlNode (typically an XmlDocument), or an XPathDocument containing the style sheet.

Exceções

O valor stylesheet é null.The stylesheet value is null.

A folha de estilos contém um erro.The style sheet contains an error.

Exemplos

O exemplo a seguir carrega uma folha de estilos contida XPathDocument em um objeto.The following example loads a style sheet contained in an XPathDocument object.

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(new XPathDocument("http://serverName/data/xsl/sort.xsl"));
Dim xslt As New XslCompiledTransform()
xslt.Load(New XPathDocument("http://serverName/data/xsl/sort.xsl"))

Comentários

A XslCompiledTransform classe dá suporte à sintaxe XSLT 1,0.The XslCompiledTransform class supports the XSLT 1.0 syntax. A folha de estilos XSLT deve usar http://www.w3.org/1999/XSL/Transform o namespace.The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

Esse método tem o seguinte comportamento:This method has the following behavior:

  • Um XmlUrlResolver sem credenciais de usuário é usado para processar qualquer xsl:import elemento xsl:include ou.An XmlUrlResolver with no user credentials is used to process any xsl:import or xsl:include elements.

  • A document() função está desabilitada.The document() function is disabled.

  • Não há suporte para scripts inseridos.Embedded scripts are not supported.

Você pode usar a Load sobrecarga para especificar um XmlResolver com as credenciais de autenticação necessárias ou para especificar diferentes configurações de XSLT.You can use the Load overload to specify an XmlResolver with the necessary authentication credentials, or to specify different XSLT settings.

Veja também

Aplica-se a