XslTransform.Transform Metoda

Definicja

Przekształca dane XML przy użyciu załadowanego arkusza stylów XSLT.

Przeciążenia

Transform(XPathNavigator, XsltArgumentList, XmlResolver)

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość XmlReader.

Transform(XPathNavigator, XsltArgumentList, TextWriter, XmlResolver)

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość TextWriter.

Transform(XPathNavigator, XsltArgumentList, Stream, XmlResolver)

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość Stream.

Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver)

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość XmlWriter.

Transform(IXPathNavigable, XsltArgumentList, TextWriter, XmlResolver)

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość TextWriter.

Transform(IXPathNavigable, XsltArgumentList, Stream, XmlResolver)

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość Stream.

Transform(XPathNavigator, XsltArgumentList, XmlWriter)
Nieaktualne.

Przekształca dane XML w obiekcie XPathNavigator przy użyciu określonych args i generuje wynik na wartość XmlWriter.

Transform(XPathNavigator, XsltArgumentList, TextWriter)
Nieaktualne.

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość TextWriter.

Transform(String, String, XmlResolver)

Przekształca dane XML w pliku wejściowym i zwraca wynik do pliku wyjściowego.

Transform(IXPathNavigable, XsltArgumentList, XmlWriter)
Nieaktualne.

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość XmlWriter.

Transform(IXPathNavigable, XsltArgumentList, XmlResolver)

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość XmlReader.

Transform(IXPathNavigable, XsltArgumentList, TextWriter)
Nieaktualne.

Przekształca dane XML w IXPathNavigable obiekcie przy użyciu określonego args elementu i generuje wynik na TextWriterwartość .

Transform(IXPathNavigable, XsltArgumentList, Stream)
Nieaktualne.

Przekształca dane XML w IXPathNavigable obiekcie przy użyciu określonego args elementu i generuje wynik na Streamwartość .

Transform(XPathNavigator, XsltArgumentList, XmlWriter, XmlResolver)

Przekształca dane XML w obiekcie XPathNavigator przy użyciu określonych args i generuje wynik na wartość XmlWriter.

Transform(XPathNavigator, XsltArgumentList)
Nieaktualne.

Przekształca dane XML w obiekcie XPathNavigator przy użyciu określonej args wartości i zwraca wynik do .XmlReader

Transform(IXPathNavigable, XsltArgumentList)
Nieaktualne.

Przekształca dane XML w obiekcie IXPathNavigable przy użyciu określonej args wartości i zwraca wynik do .XmlReader

Transform(String, String)
Nieaktualne.

Przekształca dane XML w pliku wejściowym i zwraca wynik do pliku wyjściowego.

Transform(XPathNavigator, XsltArgumentList, Stream)
Nieaktualne.

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość Stream.

Uwagi

Uwaga

Klasa XslTransform jest przestarzała w .NET Framework w wersji 2.0. Klasa XslCompiledTransform jest nowym procesorem XSLT. Aby uzyskać więcej informacji, zobacz Using the XslCompiledTransform Class (Używanie klasy XslCompiledTransform) i Migrating From the XslTransform Class (Migrowanie z klasy XslTransform).

Transform(XPathNavigator, XsltArgumentList, XmlResolver)

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość XmlReader.

public:
 System::Xml::XmlReader ^ Transform(System::Xml::XPath::XPathNavigator ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::Xml::XmlResolver ^ resolver);
public System.Xml.XmlReader Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList? args, System.Xml.XmlResolver? resolver);
public System.Xml.XmlReader Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlResolver resolver);
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlResolver -> System.Xml.XmlReader
Public Function Transform (input As XPathNavigator, args As XsltArgumentList, resolver As XmlResolver) As XmlReader

Parametry

input
XPathNavigator

Element XPathNavigator zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

resolver
XmlResolver

Służy XmlResolver do rozpoznawania funkcji document() XSLT. Jeśli jest nullto , funkcja document() nie jest rozpoznawana.

Element XmlResolver nie jest buforowany po zakończeniu Transform(XPathNavigator, XsltArgumentList, XmlResolver) metody.

Zwraca

XmlReader

Element XmlReader zawierający wyniki transformacji.

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Opcje przekształcania mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli bieżący węzeł jest ustawiony w drzewie węzła innym niż węzeł główny dokumentu, nie uniemożliwia to procesu przekształcania dostępu do wszystkich węzłów w załadowanym dokumencie. Po wykonaniu XPathNavigator transformacji pozostaje w oryginalnym stanie. Oznacza to, że węzeł, który jest bieżący przed procesem przekształcania, pozostaje bieżącym węzłem po Transform wywołaniu metody.

Ponieważ XmlReader udostępnia dane wyjściowe tylko do odczytu, xsl:output element jest ignorowany. Aby uzyskać więcej informacji, zobacz Outputs from an XslTransform (Dane wyjściowe z elementu XslTransform ).

Ta metoda umożliwia wykonywanie asynchronicznej transformacji dokumentu źródłowego.

Zobacz też

Dotyczy

Transform(XPathNavigator, XsltArgumentList, TextWriter, XmlResolver)

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość TextWriter.

public:
 void Transform(System::Xml::XPath::XPathNavigator ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::IO::TextWriter ^ output, System::Xml::XmlResolver ^ resolver);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList? args, System.IO.TextWriter output, System.Xml.XmlResolver? resolver);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output, System.Xml.XmlResolver resolver);
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter * System.Xml.XmlResolver -> unit
Public Sub Transform (input As XPathNavigator, args As XsltArgumentList, output As TextWriter, resolver As XmlResolver)

Parametry

input
XPathNavigator

Element XPathNavigator zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
TextWriter

Element TextWriter , do którego chcesz uzyskać dane wyjściowe.

resolver
XmlResolver

Służy XmlResolver do rozpoznawania funkcji document() XSLT. Jeśli jest nullto , funkcja document() nie jest rozpoznawana.

Element XmlResolver nie jest buforowany po zakończeniu Transform(XPathNavigator, XsltArgumentList, TextWriter, XmlResolver) metody.

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Opcje przekształcania mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli bieżący węzeł jest ustawiony w drzewie węzła innym niż węzeł główny dokumentu, nie uniemożliwia to procesu przekształcania dostępu do wszystkich węzłów w załadowanym dokumencie. Po wykonaniu XPathNavigator transformacji pozostaje w oryginalnym stanie. Oznacza to, że węzeł, który jest bieżący przed procesem przekształcania, pozostaje bieżącym węzłem po Transform wywołaniu metody.

Atrybut kodowania elementu xsl:output nie jest obsługiwany podczas generowania danych wyjściowych do elementu TextWriter. Zobacz Dane wyjściowe z elementu XslTransform , aby uzyskać szczegółowe informacje o obsługiwanych xsl:output atrybutach.

Zobacz też

Dotyczy

Transform(XPathNavigator, XsltArgumentList, Stream, XmlResolver)

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość Stream.

public:
 void Transform(System::Xml::XPath::XPathNavigator ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::IO::Stream ^ output, System::Xml::XmlResolver ^ resolver);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList? args, System.IO.Stream output, System.Xml.XmlResolver? resolver);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.IO.Stream output, System.Xml.XmlResolver resolver);
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.IO.Stream * System.Xml.XmlResolver -> unit
Public Sub Transform (input As XPathNavigator, args As XsltArgumentList, output As Stream, resolver As XmlResolver)

Parametry

input
XPathNavigator

Element XPathNavigator zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
Stream

Strumień, do którego chcesz uzyskać dane wyjściowe.

resolver
XmlResolver

Służy XmlResolver do rozpoznawania funkcji document() XSLT. Jeśli jest nullto , funkcja document() nie jest rozpoznawana.

Element XmlResolver nie jest buforowany po zakończeniu Transform(XPathNavigator, XsltArgumentList, Stream, XmlResolver) metody.

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Przykłady

Poniższy przykład ładuje tabelę klienta do tabeli XmlDataDocument i wykonuje przekształcenie XSLT w celu ściągnięcia danych klienta do tabeli HTML. W przykładzie użyto bazy danych Microsoft SQL Server 2000 Northwind.

using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

public class Sample
{
  public static void Main()
  {

     // Create a DataSet and load it with customer data.
     DataSet dsNorthwind = new DataSet();
     String sConnect;
     sConnect="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind";
     SqlConnection nwconnect = new SqlConnection(sConnect);
     String sCommand = "Select * from Customers where Region='WA'";
     SqlDataAdapter myDataAdapter = new SqlDataAdapter(sCommand, nwconnect);
     myDataAdapter.Fill(dsNorthwind,"Customers");

     // Load the DataSet into an XmlDataDocument.
     XmlDataDocument doc = new XmlDataDocument(dsNorthwind);

     // Create the XslTransform object and load the stylesheet.
     XslTransform xsl = new XslTransform();
     xsl.Load("customers.xsl");

     // Create an XPathNavigator to use in the transform.
     XPathNavigator nav = doc.CreateNavigator();

     // Create a FileStream object.
     FileStream fs = new FileStream("cust.html", FileMode.Create);

     // Transform the data.
     xsl.Transform(nav, null, fs, null);
  }
}
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl

public class Sample

  public shared sub Main()

     ' Create a DataSet and load it with customer data.
     Dim dsNorthwind as DataSet = new DataSet()        
     Dim sConnect as String           
     sConnect="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind"     
     Dim nwconnect as SqlConnection
     nwconnect = new SqlConnection(sConnect)
     Dim sCommand as String = "Select * from Customers where Region='WA'"
     Dim myDataAdapter as SqlDataAdapter
     myDataAdapter = new SqlDataAdapter(sCommand, nwconnect)
     myDataAdapter.Fill(dsNorthwind,"Customers")

     ' Load the DataSet into an XmlDataDocument.
     Dim doc as XmlDataDocument = new XmlDataDocument(dsNorthwind)   

     ' Create the XslTransform object and load the stylesheet.
     Dim xsl as XslTransform = new XslTransform()     
     xsl.Load("customers.xsl")

     ' Create an XPathNavigator to use in the transform.
     Dim nav as XPathNavigator = doc.CreateNavigator()

     ' Create a FileStream object.
     Dim fs as FileStream = new FileStream("cust.html", FileMode.Create)
 
     ' Transform the data.
     xsl.Transform(nav, nothing, fs, nothing)
    
  end sub
end class

W przykładzie użyto customers.xsl pliku jako danych wejściowych.

<!-- Stylesheet to sort customers by city-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template match="NewDataSet">
    <HTML>
      <BODY>
        <TABLE BORDER="2">
          <TR>
            <TD>Company Name</TD>
            <TD>Contact Name</TD>
            <TD>City</TD>
          </TR>
         <xsl:apply-templates select="Customers">
            <xsl:sort select="City"/>
         </xsl:apply-templates>
        </TABLE>
      </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="Customers">
    <TR>
      <TD><xsl:value-of select="CompanyName"/></TD>
      <TD><xsl:value-of select="ContactName"/></TD>
      <TD><xsl:value-of select="City"/></TD>
    </TR>
  </xsl:template>

</xsl:stylesheet>

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Opcje przekształcania mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli bieżący węzeł jest ustawiony w drzewie węzła innym niż węzeł główny dokumentu, nie uniemożliwia to procesu przekształcania dostępu do wszystkich węzłów w załadowanym dokumencie. Po wykonaniu XPathNavigator transformacji pozostaje w oryginalnym stanie. Oznacza to, że węzeł, który jest bieżący przed procesem przekształcania, pozostaje bieżącym węzłem po Transform wywołaniu metody.

Zobacz Dane wyjściowe z elementu XslTransform , aby uzyskać szczegółowe informacje o obsługiwanych xsl:output atrybutach.

Zobacz też

Dotyczy

Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver)

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość XmlWriter.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::Xml::XmlWriter ^ output, System::Xml::XmlResolver ^ resolver);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? args, System.Xml.XmlWriter output, System.Xml.XmlResolver? resolver);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlWriter output, System.Xml.XmlResolver resolver);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter * System.Xml.XmlResolver -> unit
Public Sub Transform (input As IXPathNavigable, args As XsltArgumentList, output As XmlWriter, resolver As XmlResolver)

Parametry

input
IXPathNavigable

Obiekt implementowania interfejsu IXPathNavigable . W .NET Framework może to być element XmlNode (zazwyczaj XmlDocument) lub XPathDocument zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
XmlWriter

Element XmlWriter , do którego chcesz uzyskać dane wyjściowe.

resolver
XmlResolver

Służy XmlResolver do rozpoznawania funkcji document() XSLT. Jeśli jest nullto , funkcja document() nie jest rozpoznawana.

Element XmlResolver nie jest buforowany po zakończeniu Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) metody.

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Przykłady

Poniższy przykład przekształca dokument XML w dokument HTML. Wyświetla on isBN, tytuł i cenę dla każdej książki w tabeli.

#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Xsl;
using namespace System::Xml::XPath;

int main()
{
   String^ filename = "books.xml";
   String^ stylesheet = "output.xsl";

   //Load the stylesheet.
   XslTransform^ xslt = gcnew XslTransform;
   xslt->Load( stylesheet );

   //Load the file to transform.
   XPathDocument^ doc = gcnew XPathDocument( filename );

   //Create an XmlTextWriter which outputs to the console.
   XmlTextWriter^ writer = gcnew XmlTextWriter( Console::Out );

   //Transform the file and send the output to the console.
   xslt->Transform(doc,nullptr,writer,nullptr);
   writer->Close();
}
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public class Sample
{
  private const String filename = "books.xml";
  private const String stylesheet = "output.xsl";

  public static void Main()
  {
    //Load the stylesheet.
    XslTransform xslt = new XslTransform();
    xslt.Load(stylesheet);

    //Load the file to transform.
    XPathDocument doc = new XPathDocument(filename);

    //Create an XmlTextWriter which outputs to the console.
    XmlTextWriter writer = new XmlTextWriter(Console.Out);

    //Transform the file and send the output to the console.
    xslt.Transform(doc, null, writer, null);
    writer.Close();
  }
}
Option Strict
Option Explicit

Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath

Public Class Sample
    Private Shared filename1 As String = "books.xml"
    Private Shared stylesheet1 As String = "output.xsl"
    
    
    Public Shared Sub Main()
        'Load the stylesheet.
        Dim xslt As New XslTransform()
        xslt.Load(stylesheet1)
        
        'Load the file to transform.
        Dim doc As New XPathDocument(filename1)
        
        'Create an XmlTextWriter which outputs to the console.
        Dim writer As New XmlTextWriter(Console.Out)
        
        'Transform the file and send the output to the console.
        xslt.Transform(doc, Nothing, writer, Nothing)
        writer.Close()
    End Sub
End Class

W przykładzie użyto następujących dwóch plików wejściowych.

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>

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Element xsl:output nie jest obsługiwany podczas generowania danych wyjściowych do elementu XmlWriter (xsl:output jest ignorowany). Aby uzyskać więcej informacji, zobacz Outputs from an XslTransform (Dane wyjściowe z elementu XslTransform ).

Przekształcenia mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli przekazujesz węzeł inny niż węzeł główny dokumentu, nie zapobiega to uzyskiwaniu dostępu do wszystkich węzłów w załadowanym dokumencie. Aby przekształcić fragment węzła, należy utworzyć XmlDocument element zawierający tylko fragment węzła i przekazać go XmlDocument do Transform metody .

Poniższy przykład wykonuje przekształcenie fragmentu węzła.

XslTransform xslt = new XslTransform();       
xslt.Load("print_root.xsl");  
XmlDocument doc = new XmlDocument();  
doc.Load("library.xml");  
// Create a new document containing just the node fragment.  
XmlNode testNode = doc.DocumentElement.FirstChild;   
XmlDocument tmpDoc = new XmlDocument();   
tmpDoc.LoadXml(testNode.OuterXml);  
// Pass the document containing the node fragment   
// to the Transform method.  
Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");  
xslt.Transform(tmpDoc, null, Console.Out, null);  

W przykładzie użyto library.xml plików i print_root.xsl jako danych wejściowych i wyjściowych w konsoli programu .

Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl   
Root node is book.  

library.xml

<library>  
  <book genre='novel' ISBN='1-861001-57-5'>  
     <title>Pride And Prejudice</title>  
  </book>  
  <book genre='novel' ISBN='1-81920-21-2'>  
     <title>Hook</title>  
  </book>  
</library>  

print_root.xsl

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" >  
  <output method="text" />  
  <template match="/">  
  Root node is  <value-of select="local-name(//*[position() = 1])" />   
  </template>  
</stylesheet>  

Zobacz też

Dotyczy

Transform(IXPathNavigable, XsltArgumentList, TextWriter, XmlResolver)

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość TextWriter.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::IO::TextWriter ^ output, System::Xml::XmlResolver ^ resolver);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? args, System.IO.TextWriter output, System.Xml.XmlResolver? resolver);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output, System.Xml.XmlResolver resolver);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter * System.Xml.XmlResolver -> unit
Public Sub Transform (input As IXPathNavigable, args As XsltArgumentList, output As TextWriter, resolver As XmlResolver)

Parametry

input
IXPathNavigable

Obiekt implementowania interfejsu IXPathNavigable . W .NET Framework może to być element XmlNode (zazwyczaj XmlDocument) lub XPathDocument zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
TextWriter

Element TextWriter , do którego chcesz uzyskać dane wyjściowe.

resolver
XmlResolver

Służy XmlResolver do rozpoznawania funkcji document() XSLT. Jeśli jest nullto , funkcja document() nie jest rozpoznawana.

Element XmlResolver nie jest buforowany po zakończeniu Transform(IXPathNavigable, XsltArgumentList, TextWriter, XmlResolver) metody.

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Przykłady

Poniższy przykład przekształca plik XML i generuje ciąg HTML. Klasy StringReader i StringWriter służą do odczytywania i zapisywania ciągów.

using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public class Sample {

  public static void Main() {

    // Create a string containing the XSLT stylesheet.
    String xsltString =
    @"<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
        <xsl:template match='bookstore'>
           <HTML>
              <HEAD>
                 <TITLE>Book Titles</TITLE>
             </HEAD>
             <BODY>
                <xsl:apply-templates select='book'/>
             </BODY>
          </HTML>
        </xsl:template>
        <xsl:template match='book'>
          <P><xsl:value-of select='title'/></P>
        </xsl:template>
        </xsl:stylesheet>";

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

    // Load the stylesheet.
    StringReader rdr = new StringReader(xsltString);
    xslt.Load(new XPathDocument(rdr), null, null);

    // Transform the file and output an HTML string.
    string HTMLoutput;
    StringWriter writer = new StringWriter();
    xslt.Transform(new XPathDocument("books.xml"), null, writer, null);
    HTMLoutput = writer.ToString();
  }
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath

public class Sample 

  public shared sub Main() 
   
    ' Create a string containing the XSLT stylesheet.
    Dim xsltString as String 
    xsltString = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>" & _
    "   <xsl:template match='bookstore'>" & _
    "      <HTML>" & _
    "         <HEAD>" & _
    "            <TITLE>Book Titles</TITLE>" & _
    "       </HEAD>" & _
    "        <BODY>" & _
    "           <xsl:apply-templates select='book'/>" & _
    "        </BODY>" & _
    "     </HTML>" & _
    "   </xsl:template>" & _
    "  <xsl:template match='book'>" & _
    "     <P><xsl:value-of select='title'/></P>" & _
    "   </xsl:template>" & _
    "   </xsl:stylesheet>"

    ' Create the XslTransform object.
    Dim xslt as XslTransform = new XslTransform()

    ' Load the stylesheet.
    Dim rdr as StringReader = new StringReader(xsltString)
    xslt.Load(new XPathDocument(rdr), nothing, nothing)

    ' Transform the file and output an HTML string.
    Dim HTMLoutput as string
    Dim writer as StringWriter = new StringWriter()
    xslt.Transform(new XPathDocument("books.xml"), nothing, writer, nothing)
    HTMLoutput = writer.ToString()

  end sub
end class

W przykładzie użyto books.xml pliku jako danych wejściowych.

<?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>

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów.

Atrybut kodowania elementu xsl:output nie jest obsługiwany podczas generowania danych wyjściowych do elementu TextWriter. Zobacz Dane wyjściowe z elementu XslTransform , aby uzyskać szczegółowe informacje o obsługiwanych xsl:output atrybutach.

Przekształcenia mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli przekazujesz węzeł inny niż węzeł główny dokumentu, nie zapobiega to uzyskiwaniu dostępu do wszystkich węzłów w załadowanym dokumencie. Aby przekształcić fragment węzła, należy utworzyć XmlDocument element zawierający tylko fragment węzła i przekazać go XmlDocument do Transform metody .

Poniższy przykład wykonuje przekształcenie fragmentu węzła.

XslTransform xslt = new XslTransform();       
xslt.Load("print_root.xsl");  
XmlDocument doc = new XmlDocument();  
doc.Load("library.xml");  
// Create a new document containing just the node fragment.  
XmlNode testNode = doc.DocumentElement.FirstChild;   
XmlDocument tmpDoc = new XmlDocument();   
tmpDoc.LoadXml(testNode.OuterXml);  
// Pass the document containing the node fragment   
// to the Transform method.  
Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");  
xslt.Transform(tmpDoc, null, Console.Out, null);  

W przykładzie użyto library.xml plików i print_root.xsl jako danych wejściowych i wyjściowych w konsoli programu .

Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl   
Root node is book.  

library.xml

<library>  
  <book genre='novel' ISBN='1-861001-57-5'>  
     <title>Pride And Prejudice</title>  
  </book>  
  <book genre='novel' ISBN='1-81920-21-2'>  
     <title>Hook</title>  
  </book>  
</library>  

print_root.xsl

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" >  
  <output method="text" />   
  <template match="/">  
     Root node is  <value-of select="local-name(//*[position() = 1])" />   
  </template>  
</stylesheet>  

Zobacz też

Dotyczy

Transform(IXPathNavigable, XsltArgumentList, Stream, XmlResolver)

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość Stream.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::IO::Stream ^ output, System::Xml::XmlResolver ^ resolver);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? args, System.IO.Stream output, System.Xml.XmlResolver? resolver);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.IO.Stream output, System.Xml.XmlResolver resolver);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.Stream * System.Xml.XmlResolver -> unit
Public Sub Transform (input As IXPathNavigable, args As XsltArgumentList, output As Stream, resolver As XmlResolver)

Parametry

input
IXPathNavigable

Obiekt implementowania interfejsu IXPathNavigable . W .NET Framework może to być element XmlNode (zazwyczaj XmlDocument) lub XPathDocument zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
Stream

Strumień, do którego chcesz uzyskać dane wyjściowe.

resolver
XmlResolver

Służy XmlResolver do rozpoznawania funkcji document() XSLT. Jeśli jest nullto , funkcja document() nie jest rozpoznawana.

Element XmlResolver nie jest buforowany po zakończeniu Transform metody.

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Przykłady

Poniższy przykład wykonuje przekształcenie na stronie ASP.NET.

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ import NameSpace="System.Web" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<html>
   <script language="C#" runat="server">
      void Page_Load(Object sender, EventArgs e) 
      {
         // Load the XML document to transform.
         XPathDocument doc = new XPathDocument(Server.MapPath("books.xml"));

         // Load the stylesheet and perform the transform.
         XslTransform xslt = new XslTransform();
         xslt.Load(Server.MapPath("output.xsl"));
         xslt.Transform(doc, null, Response.OutputStream, null);
        
      }
   </script>
</html>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ import NameSpace="System.Web" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<html>
   <script language="VB" runat="server">
      sub Page_Load(sender as Object, e as EventArgs) 

         ' Load the XML document to transform.
         dim doc as XPathDocument = new XPathDocument(Server.MapPath("books.xml"))

         ' Load the stylesheet and perform the transform.
         dim xslt as XslTransform = new XslTransform()
         xslt.Load(Server.MapPath("output.xsl"))
         xslt.Transform(doc, nothing, Response.OutputStream, nothing)
        
      end sub
   </script>
</html>

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów.

Przekształcenia mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli przekazujesz węzeł inny niż węzeł główny dokumentu, nie zapobiega to uzyskiwaniu dostępu do wszystkich węzłów w załadowanym dokumencie. Aby przekształcić fragment węzła, należy utworzyć XmlDocument element zawierający tylko fragment węzła i przekazać go XmlDocument do Transform metody .

Poniższy przykład wykonuje przekształcenie fragmentu węzła.

XslTransform xslt = new XslTransform();       
xslt.Load("print_root.xsl");  
XmlDocument doc = new XmlDocument();  
doc.Load("library.xml");  
// Create a new document containing just the node fragment.  
XmlNode testNode = doc.DocumentElement.FirstChild;   
XmlDocument tmpDoc = new XmlDocument();   
tmpDoc.LoadXml(testNode.OuterXml);  
// Pass the document containing the node fragment   
// to the Transform method.  
Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");  
xslt.Transform(tmpDoc, null, Console.Out, null);  

W przykładzie użyto library.xml plików i print_root.xsl jako danych wejściowych i wyjściowych w konsoli programu .

Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl   
Root node is book.  

library.xml

<library>  
  <book genre='novel' ISBN='1-861001-57-5'>  
     <title>Pride And Prejudice</title>  
  </book>  
  <book genre='novel' ISBN='1-81920-21-2'>  
     <title>Hook</title>  
  </book>  
</library>  

print_root.xsl

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" >  
  <output method="text" />   
  <template match="/">  
     Root node is  <value-of select="local-name(//*[position() = 1])" />   
  </template>  
</stylesheet>  

Zobacz też

Dotyczy

Transform(XPathNavigator, XsltArgumentList, XmlWriter)

Przestroga

You should pass XmlResolver to Transform() method

Przekształca dane XML w obiekcie XPathNavigator przy użyciu określonych args i generuje wynik na wartość XmlWriter.

public:
 void Transform(System::Xml::XPath::XPathNavigator ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::Xml::XmlWriter ^ output);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList? args, System.Xml.XmlWriter output);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlWriter output);
[System.Obsolete("You should pass XmlResolver to Transform() method")]
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlWriter output);
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
[<System.Obsolete("You should pass XmlResolver to Transform() method")>]
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
Public Sub Transform (input As XPathNavigator, args As XsltArgumentList, output As XmlWriter)

Parametry

input
XPathNavigator

Element XPathNavigator zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
XmlWriter

Element XmlWriter , do którego chcesz uzyskać dane wyjściowe.

Atrybuty

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Opcje przekształcania mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli bieżący węzeł jest ustawiony w drzewie węzła innym niż węzeł główny dokumentu, nie uniemożliwia to procesu przekształcania dostępu do wszystkich węzłów w załadowanym dokumencie. Po wykonaniu XPathNavigator transformacji pozostaje w oryginalnym stanie. Oznacza to, że węzeł, który jest bieżący przed procesem przekształcania, pozostaje bieżącym węzłem po Transform wywołaniu metody.

Element xsl:output nie jest obsługiwany podczas generowania danych wyjściowych do elementu XmlWriter (xsl:output jest ignorowany). Aby uzyskać więcej informacji, zobacz Outputs from an XslTransform (Dane wyjściowe z elementu XslTransform ).

Uwaga

Ta metoda jest teraz przestarzała. Ustawienie XmlResolver właściwości określa sposób rozpoznawania funkcji XSLT document() . Zalecaną praktyką jest użycie Transform metody, która przyjmuje XmlResolver obiekt jako jeden z jego argumentów.

Zobacz też

Dotyczy

Transform(XPathNavigator, XsltArgumentList, TextWriter)

Przestroga

You should pass XmlResolver to Transform() method

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość TextWriter.

public:
 void Transform(System::Xml::XPath::XPathNavigator ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::IO::TextWriter ^ output);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList? args, System.IO.TextWriter output);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output);
[System.Obsolete("You should pass XmlResolver to Transform() method")]
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output);
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
[<System.Obsolete("You should pass XmlResolver to Transform() method")>]
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
Public Sub Transform (input As XPathNavigator, args As XsltArgumentList, output As TextWriter)

Parametry

input
XPathNavigator

Element XPathNavigator zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
TextWriter

Element TextWriter , do którego chcesz uzyskać dane wyjściowe.

Atrybuty

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Opcje przekształcania mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli bieżący węzeł jest ustawiony w drzewie węzła innym niż węzeł główny dokumentu, nie uniemożliwia to procesu przekształcania dostępu do wszystkich węzłów w załadowanym dokumencie. Po wykonaniu XPathNavigator transformacji pozostaje w oryginalnym stanie. Oznacza to, że węzeł, który jest bieżący przed procesem przekształcania, pozostaje bieżącym węzłem po Transform wywołaniu metody.

Atrybut kodowania elementu xsl:output nie jest obsługiwany podczas generowania danych wyjściowych do elementu TextWriter. Zobacz Dane wyjściowe z elementu XslTransform , aby uzyskać szczegółowe informacje o obsługiwanych xsl:output atrybutach.

Uwaga

Ta metoda jest teraz przestarzała. Ustawienie XmlResolver właściwości określa sposób rozpoznawania funkcji XSLT document() . Zalecaną praktyką jest użycie Transform metody, która przyjmuje XmlResolver obiekt jako jeden z jego argumentów.

Zobacz też

Dotyczy

Transform(String, String, XmlResolver)

Przekształca dane XML w pliku wejściowym i zwraca wynik do pliku wyjściowego.

public:
 void Transform(System::String ^ inputfile, System::String ^ outputfile, System::Xml::XmlResolver ^ resolver);
public void Transform (string inputfile, string outputfile, System.Xml.XmlResolver? resolver);
public void Transform (string inputfile, string outputfile, System.Xml.XmlResolver resolver);
member this.Transform : string * string * System.Xml.XmlResolver -> unit
Public Sub Transform (inputfile As String, outputfile As String, resolver As XmlResolver)

Parametry

inputfile
String

Adres URL dokumentu źródłowego, który ma zostać przekształcony.

outputfile
String

Adres URL pliku wyjściowego.

resolver
XmlResolver

Funkcja XmlResolver używana do rozpoznawania funkcji document() XSLT. Jeśli jest nullto wartość , funkcja document() nie jest rozpoznawana.

Wartość XmlResolver nie jest buforowana po zakończeniu Transform metody.

Przykłady

Poniższy przykład wykonuje przekształcenie XSLT i dane wyjściowe do pliku. Element XmlUrlResolver z poświadczeniami domyślnymi jest używany do rozpoznawania zasobów zewnętrznych. Aby uzyskać szczegółowe informacje, zobacz opis funkcji DefaultCredentials.

// Create a resolver with default credentials.
XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
resolver->Credentials = System::Net::CredentialCache::DefaultCredentials;

// Create the XslTransform object.
XslTransform^ xslt = gcnew XslTransform;

// Load the stylesheet.
xslt->Load( "http://myServer/data/authors.xsl", resolver );

// Transform the file.
xslt->Transform( "books.xml", "books.html", resolver );

// Create a resolver with default credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

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

// Load the stylesheet.
xslt.Load("http://myServer/data/authors.xsl", resolver);

// Transform the file.
xslt.Transform("books.xml", "books.html", resolver);

' Create a resolver with default credentials.
Dim resolver as XmlUrlResolver = new XmlUrlResolver()
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials

' Create the XslTransform object.
Dim xslt as XslTransform = new XslTransform()

' Load the stylesheet.
xslt.Load("http://myServer/data/authors.xsl", resolver)

' Transform the file. 
xslt.Transform("books.xml", "titles.xml", resolver)

Uwagi

Uwaga

Klasa XslTransform jest przestarzała w .NET Framework w wersji 2.0. Klasa XslCompiledTransform jest nowym procesorem XSLT. Aby uzyskać więcej informacji, zobacz Using the XslCompiledTransform Class (Używanie klasy XslCompiledTransform) i Migrating From the XslTransform Class (Migrowanie z klasy XslTransform).

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Zobacz też

Dotyczy

Transform(IXPathNavigable, XsltArgumentList, XmlWriter)

Przestroga

You should pass XmlResolver to Transform() method

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość XmlWriter.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::Xml::XmlWriter ^ output);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? args, System.Xml.XmlWriter output);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlWriter output);
[System.Obsolete("You should pass XmlResolver to Transform() method")]
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlWriter output);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
[<System.Obsolete("You should pass XmlResolver to Transform() method")>]
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
Public Sub Transform (input As IXPathNavigable, args As XsltArgumentList, output As XmlWriter)

Parametry

input
IXPathNavigable

Obiekt implementowania interfejsu IXPathNavigable . W .NET Framework może to być element XmlNode (zazwyczaj XmlDocument) lub XPathDocument zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
XmlWriter

Element XmlWriter , do którego chcesz uzyskać dane wyjściowe.

Atrybuty

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Uwaga

Ta metoda jest teraz przestarzała. Ustawienie XmlResolver właściwości określa sposób rozpoznawania funkcji XSLT document() . Zalecaną praktyką jest użycie Transform metody, która przyjmuje XmlResolver obiekt jako jeden z jego argumentów.

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Element xsl:output nie jest obsługiwany podczas generowania danych wyjściowych do elementu XmlWriter (xsl:output jest ignorowany). Aby uzyskać więcej informacji, zobacz Outputs from an XslTransform (Dane wyjściowe z elementu XslTransform ).

Przekształcenia mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli przekazujesz węzeł inny niż węzeł główny dokumentu, nie zapobiega to uzyskiwaniu dostępu do wszystkich węzłów w załadowanym dokumencie. Aby przekształcić fragment węzła, należy utworzyć XmlDocument element zawierający tylko fragment węzła i przekazać go XmlDocument do Transform metody .

Poniższy przykład wykonuje przekształcenie fragmentu węzła.

XslTransform xslt = new XslTransform();       
xslt.Load("print_root.xsl");  
XmlDocument doc = new XmlDocument();  
doc.Load("library.xml");  
// Create a new document containing just the node fragment.  
XmlNode testNode = doc.DocumentElement.FirstChild;   
XmlDocument tmpDoc = new XmlDocument();   
tmpDoc.LoadXml(testNode.OuterXml);  
// Pass the document containing the node fragment   
// to the Transform method.  
Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");  
xslt.Transform(tmpDoc, null, Console.Out);  

W przykładzie użyto library.xml plików i print_root.xsl jako danych wejściowych i wyjściowych w konsoli programu .

Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl   
Root node is book.  

library.xml

<library>  
  <book genre='novel' ISBN='1-861001-57-5'>  
     <title>Pride And Prejudice</title>  
  </book>  
  <book genre='novel' ISBN='1-81920-21-2'>  
     <title>Hook</title>  
  </book>  
</library>  

print_root.xsl

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" >  
  <output method="text" />  
  <template match="/">  
  Root node is  <value-of select="local-name(//*[position() = 1])" />   
  </template>  
</stylesheet>  

Zobacz też

Dotyczy

Transform(IXPathNavigable, XsltArgumentList, XmlResolver)

Przekształca dane XML w elemecie IXPathNavigable przy użyciu określonej wartości args i generuje wynik na wartość XmlReader.

public:
 System::Xml::XmlReader ^ Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::Xml::XmlResolver ^ resolver);
public System.Xml.XmlReader Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? args, System.Xml.XmlResolver? resolver);
public System.Xml.XmlReader Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlResolver resolver);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlResolver -> System.Xml.XmlReader
Public Function Transform (input As IXPathNavigable, args As XsltArgumentList, resolver As XmlResolver) As XmlReader

Parametry

input
IXPathNavigable

Obiekt implementowania interfejsu IXPathNavigable . W .NET Framework może to być element XmlNode (zazwyczaj XmlDocument) lub XPathDocument zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

resolver
XmlResolver

Służy XmlResolver do rozpoznawania funkcji document() XSLT. Jeśli jest nullto , funkcja document() nie jest rozpoznawana.

Element XmlResolver nie jest buforowany po zakończeniu Transform(IXPathNavigable, XsltArgumentList, XmlResolver) metody.

Zwraca

XmlReader

Element XmlReader zawierający wyniki transformacji.

Przykłady

Poniższy przykład przekształca dokument XML i zwraca wyniki do elementu XmlReader. Element XmlUrlResolver z wymaganymi poświadczeniami służy do przetwarzania dowolnych funkcji XSLT document() .

// Create the XslTransform object.
XslTransform^ xslt = gcnew XslTransform;

// Load the stylesheet.
xslt->Load( "titles.xsl" );

// Create a resolver and specify the necessary credentials.
XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
System::Net::NetworkCredential^ myCred;
myCred = gcnew System::Net::NetworkCredential( UserName, SecurelyStoredPassword, Domain );
resolver->Credentials = myCred;

// Transform the file using the resolver. The resolver is used
// to process the XSLT document() function.
XPathDocument^ doc = gcnew XPathDocument( "books.xml" );
XmlReader^ reader = xslt->Transform( doc, nullptr, resolver );

// Load the reader into a new document for more processing.
XmlDocument^ xmldoc = gcnew XmlDocument;
xmldoc->Load( reader );
// Create the XslTransform object.
XslTransform xslt = new XslTransform();

// Load the stylesheet.
xslt.Load("titles.xsl");

// 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;

// Transform the file using the resolver. The resolver is used
// to process the XSLT document() function.
XPathDocument doc = new XPathDocument("books.xml");
XmlReader reader = xslt.Transform(doc, null, resolver);

// Load the reader into a new document for more processing.
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(reader);
' Create the XslTransform object.
Dim xslt as XslTransform = new XslTransform()

' Load the stylesheet.
xslt.Load("titles.xsl")

' Create a resolver and specify the necessary credentials.
Dim resolver as XmlUrlResolver = new XmlUrlResolver()
Dim myCred as System.Net.NetworkCredential 
myCred = new System.Net.NetworkCredential(UserName,SecurelyStoredPassword,Domain)
resolver.Credentials = myCred

' Transform thefile using the resolver. The resolver is used
' to process the XSLT document() function.
Dim doc as XPathDocument = new XPathDocument("books.xml")
Dim reader as XmlReader = xslt.Transform(doc, nothing, resolver)

' Load the reader into a new document for more processing.
Dim xmldoc as XmlDocument = new XmlDocument()
xmldoc.Load(reader)

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Element xsl:output nie jest obsługiwany podczas generowania danych wyjściowych do elementu XmlReader ( xsl:output element jest ignorowany). Aby uzyskać więcej informacji, zobacz Outputs from an XslTransform (Dane wyjściowe z elementu XslTransform ).

Ta metoda umożliwia wykonywanie asynchronicznej transformacji dokumentu źródłowego.

Przekształcenia mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli przekazujesz węzeł inny niż węzeł główny dokumentu, nie zapobiega to uzyskiwaniu dostępu do wszystkich węzłów w załadowanym dokumencie. Aby przekształcić fragment węzła, należy utworzyć XmlDocument element zawierający tylko fragment węzła i przekazać go XmlDocument do Transform metody .

Poniższy przykład wykonuje przekształcenie fragmentu węzła.

XslTransform xslt = new XslTransform();       
xslt.Load("print_root.xsl");  
XmlDocument doc = new XmlDocument();  
doc.Load("library.xml");  
// Create a new document containing just the node fragment.  
XmlNode testNode = doc.DocumentElement.FirstChild;   
XmlDocument tmpDoc = new XmlDocument();   
tmpDoc.LoadXml(testNode.OuterXml);  
// Pass the document containing the node fragment   
// to the Transform method.  
Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");  
xslt.Transform(tmpDoc, null, Console.Out, null);  

W przykładzie użyto library.xml plików i print_root.xsl jako danych wejściowych i wyjściowych w konsoli programu .

Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl   
Root node is book.  

library.xml

<library>  
  <book genre='novel' ISBN='1-861001-57-5'>  
     <title>Pride And Prejudice</title>  
  </book>  
  <book genre='novel' ISBN='1-81920-21-2'>  
     <title>Hook</title>  
  </book>  
</library>  

print_root.xsl

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" >  
  <output method="text" />   
  <template match="/">  
     Root node is  <value-of select="local-name(//*[position() = 1])" />   
  </template>  
</stylesheet>  

Zobacz też

Dotyczy

Transform(IXPathNavigable, XsltArgumentList, TextWriter)

Przestroga

You should pass XmlResolver to Transform() method

Przekształca dane XML w IXPathNavigable obiekcie przy użyciu określonego args elementu i generuje wynik na TextWriterwartość .

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::IO::TextWriter ^ output);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? args, System.IO.TextWriter output);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output);
[System.Obsolete("You should pass XmlResolver to Transform() method")]
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
[<System.Obsolete("You should pass XmlResolver to Transform() method")>]
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
Public Sub Transform (input As IXPathNavigable, args As XsltArgumentList, output As TextWriter)

Parametry

input
IXPathNavigable

Obiekt implementuje IXPathNavigable interfejs. W .NET Framework może to być element XmlNode (zazwyczaj XmlDocument) lub XPathDocument zawierający dane do przekształcenia.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe przekształcenia.

output
TextWriter

Wartość TextWriter , do której ma zostać wyświetlona wartość wyjściowa.

Atrybuty

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Uwagi

Uwaga

Klasa XslTransform jest przestarzała w .NET Framework w wersji 2.0. Klasa XslCompiledTransform jest nowym procesorem XSLT. Aby uzyskać więcej informacji, zobacz Using the XslCompiledTransform Class (Używanie klasy XslCompiledTransform) i Migrating From the XslTransform Class (Migrowanie z klasy XslTransform).

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Uwaga

Ta metoda jest teraz przestarzała. Ustawienie XmlResolver właściwości określa sposób rozpoznawania funkcji XSLT document() . Zalecaną praktyką jest użycie metody , która przyjmuje Transform XmlResolver obiekt jako jeden z jego argumentów.

Element args jest dopasowywany do elementów zdefiniowanych xsl:param w arkuszu stylów.

Atrybut kodowania elementu xsl:output nie jest obsługiwany podczas wyprowadzania do elementu TextWriter. Aby uzyskać szczegółowe informacje o xsl:output obsługiwanych atrybutach, zobacz Dane wyjściowe z elementu XslTransform.

Przekształcenia mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli przekazujesz węzeł inny niż węzeł główny dokumentu, nie zapobiega to uzyskiwaniu dostępu do wszystkich węzłów w załadowanym dokumencie. Aby przekształcić fragment węzła, należy utworzyć XmlDocument element zawierający tylko fragment węzła i przekazać go XmlDocument do Transform metody .

Poniższy przykład wykonuje przekształcenie fragmentu węzła.

XslTransform xslt = new XslTransform();       
xslt.Load("print_root.xsl");  
XmlDocument doc = new XmlDocument();  
doc.Load("library.xml");  
// Create a new document containing just the node fragment.  
XmlNode testNode = doc.DocumentElement.FirstChild;   
XmlDocument tmpDoc = new XmlDocument();   
tmpDoc.LoadXml(testNode.OuterXml);  
// Pass the document containing the node fragment   
// to the Transform method.  
Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");  
xslt.Transform(tmpDoc, null, Console.Out);  

W przykładzie użyto library.xml plików i print_root.xsl jako danych wejściowych i wyjściowych w konsoli programu .

Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl   
Root node is book.  

library.xml

<library>  
  <book genre='novel' ISBN='1-861001-57-5'>  
     <title>Pride And Prejudice</title>  
  </book>  
  <book genre='novel' ISBN='1-81920-21-2'>  
     <title>Hook</title>  
  </book>  
</library>  

print_root.xsl

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" >  
  <output method="text" />   
  <template match="/">  
     Root node is  <value-of select="local-name(//*[position() = 1])" />   
  </template>  
</stylesheet>  

Zobacz też

Dotyczy

Transform(IXPathNavigable, XsltArgumentList, Stream)

Przestroga

You should pass XmlResolver to Transform() method

Przekształca dane XML w IXPathNavigable obiekcie przy użyciu określonego args elementu i generuje wynik na Streamwartość .

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::IO::Stream ^ output);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? args, System.IO.Stream output);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.IO.Stream output);
[System.Obsolete("You should pass XmlResolver to Transform() method")]
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.IO.Stream output);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
[<System.Obsolete("You should pass XmlResolver to Transform() method")>]
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
Public Sub Transform (input As IXPathNavigable, args As XsltArgumentList, output As Stream)

Parametry

input
IXPathNavigable

Obiekt implementuje IXPathNavigable interfejs. W .NET Framework może to być element XmlNode (zazwyczaj XmlDocument) lub XPathDocument zawierający dane do przekształcenia.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe przekształcenia.

output
Stream

Strumień, do którego chcesz uzyskać dane wyjściowe.

Atrybuty

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz usługi Microsoft .NET Framework w wersji 1.1 lub starszej.

Uwagi

Uwaga

Klasa XslTransform jest przestarzała w .NET Framework w wersji 2.0. Klasa XslCompiledTransform jest nowym procesorem XSLT. Aby uzyskać więcej informacji, zobacz Using the XslCompiledTransform Class (Używanie klasy XslCompiledTransform) i Migrating From the XslTransform Class (Migrowanie z klasy XslTransform).

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Uwaga

Ta metoda jest teraz przestarzała. Ustawienie XmlResolver właściwości określa sposób rozpoznawania funkcji XSLT document() . Zalecaną praktyką jest użycie metody , która przyjmuje Transform XmlResolver obiekt jako jeden z jego argumentów.

Element args jest dopasowywany do elementów zdefiniowanych xsl:param w arkuszu stylów.

Przekształcenia mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli przekazujesz węzeł inny niż węzeł główny dokumentu, nie uniemożliwia to procesowi przekształcania uzyskiwania dostępu do wszystkich węzłów w załadowanym dokumencie. Aby przekształcić fragment węzła, należy utworzyć XmlDocument obiekt zawierający tylko fragment węzła i przekazać go XmlDocument do Transform metody .

Poniższy przykład wykonuje przekształcenie na fragmentie węzła.

XslTransform xslt = new XslTransform();       
xslt.Load("print_root.xsl");  
XmlDocument doc = new XmlDocument();  
doc.Load("library.xml");  
// Create a new document containing just the node fragment.  
XmlNode testNode = doc.DocumentElement.FirstChild;   
XmlDocument tmpDoc = new XmlDocument();   
tmpDoc.LoadXml(testNode.OuterXml);  
// Pass the document containing the node fragment   
// to the Transform method.  
Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");  
xslt.Transform(tmpDoc, null, Console.Out);  

W przykładzie użyto library.xml plików i print_root.xsl jako danych wejściowych i wyjściowych w konsoli programu .

Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl   
Root node is book.  

library.xml

<library>  
  <book genre='novel' ISBN='1-861001-57-5'>  
     <title>Pride And Prejudice</title>  
  </book>  
  <book genre='novel' ISBN='1-81920-21-2'>  
     <title>Hook</title>  
  </book>  
</library>  

print_root.xsl

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" >  
  <output method="text" />   
  <template match="/">  
     Root node is  <value-of select="local-name(//*[position() = 1])" />   
  </template>  
</stylesheet>  

Zobacz też

Dotyczy

Transform(XPathNavigator, XsltArgumentList, XmlWriter, XmlResolver)

Przekształca dane XML w obiekcie XPathNavigator przy użyciu określonych args i generuje wynik na wartość XmlWriter.

public:
 void Transform(System::Xml::XPath::XPathNavigator ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::Xml::XmlWriter ^ output, System::Xml::XmlResolver ^ resolver);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList? args, System.Xml.XmlWriter output, System.Xml.XmlResolver? resolver);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlWriter output, System.Xml.XmlResolver resolver);
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter * System.Xml.XmlResolver -> unit
Public Sub Transform (input As XPathNavigator, args As XsltArgumentList, output As XmlWriter, resolver As XmlResolver)

Parametry

input
XPathNavigator

Element XPathNavigator zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
XmlWriter

Element XmlWriter , do którego chcesz uzyskać dane wyjściowe.

resolver
XmlResolver

Służy XmlResolver do rozpoznawania funkcji document() XSLT. Jeśli jest nullto , funkcja document() nie jest rozpoznawana.

Element XmlResolver nie jest buforowany po zakończeniu Transform(XPathNavigator, XsltArgumentList, XmlWriter, XmlResolver) metody.

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz usługi Microsoft .NET Framework w wersji 1.1 lub starszej.

Przykłady

Poniższy przykład ładuje i edytuje dokument XML przed wykonaniem przekształcenia XSLT.

XmlDocument^ doc = gcnew XmlDocument;
doc->Load( "books.xml" );

// Modify the XML file.
XmlElement^ root = doc->DocumentElement;
root->FirstChild->LastChild->InnerText = "12.95";

// Create an XPathNavigator to use for the transform.
XPathNavigator^ nav = root->CreateNavigator();

// Transform the file.
XslTransform^ xslt = gcnew XslTransform;
xslt->Load( "output.xsl" );
XmlTextWriter^ writer = gcnew XmlTextWriter( "books.html", nullptr );
xslt->Transform( nav, nullptr, writer, nullptr);
XmlDocument doc = new XmlDocument();
doc.Load("books.xml");

// Modify the XML file.
XmlElement root = doc.DocumentElement;
root.FirstChild.LastChild.InnerText = "12.95";

// Create an XPathNavigator to use for the transform.
XPathNavigator nav = root.CreateNavigator();

// Transform the file.
XslTransform xslt = new XslTransform();
xslt.Load("output.xsl");
XmlTextWriter writer = new XmlTextWriter("books.html", null);
xslt.Transform(nav, null, writer, null);
Dim doc as XmlDocument = new XmlDocument()
doc.Load("books.xml")

' Modify the XML file.
Dim root as XmlElement = doc.DocumentElement
root.FirstChild.LastChild.InnerText = "12.95"

' Create an XPathNavigator to use for the transform.
Dim nav as XPathNavigator = root.CreateNavigator()

' Transform the file.
Dim xslt as XslTransform = new XslTransform()
xslt.Load("output.xsl")
Dim writer as XmlTextWriter = new XmlTextWriter("books.html", nothing)
xslt.Transform(nav,nothing, writer, nothing)

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Opcje przekształcania mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli bieżący węzeł jest ustawiony w drzewie węzła innym niż węzeł główny dokumentu, nie uniemożliwia to procesu przekształcania dostępu do wszystkich węzłów w załadowanym dokumencie. Po wykonaniu XPathNavigator transformacji pozostaje w oryginalnym stanie. Oznacza to, że węzeł, który jest bieżący przed procesem przekształcania, pozostaje bieżącym węzłem po wywołaniu Transform metody.

Element xsl:output nie jest obsługiwany podczas wyprowadzania do elementu XmlWriter (xsl:output jest ignorowany). Aby uzyskać więcej informacji, zobacz Outputs from an XslTransform (Dane wyjściowe z elementu XslTransform ).

Zobacz też

Dotyczy

Transform(XPathNavigator, XsltArgumentList)

Przestroga

You should pass XmlResolver to Transform() method

Przekształca dane XML w obiekcie XPathNavigator przy użyciu określonej args wartości i zwraca wynik do .XmlReader

public:
 System::Xml::XmlReader ^ Transform(System::Xml::XPath::XPathNavigator ^ input, System::Xml::Xsl::XsltArgumentList ^ args);
public System.Xml.XmlReader Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList? args);
public System.Xml.XmlReader Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args);
[System.Obsolete("You should pass XmlResolver to Transform() method")]
public System.Xml.XmlReader Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args);
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList -> System.Xml.XmlReader
[<System.Obsolete("You should pass XmlResolver to Transform() method")>]
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList -> System.Xml.XmlReader
Public Function Transform (input As XPathNavigator, args As XsltArgumentList) As XmlReader

Parametry

input
XPathNavigator

Obiekt XPathNavigator zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe przekształcenia.

Zwraca

XmlReader

Element XmlReader zawierający wyniki przekształcenia.

Atrybuty

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz usługi Microsoft .NET Framework w wersji 1.1 lub starszej.

Uwagi

Uwaga

Klasa XslTransform jest przestarzała w .NET Framework w wersji 2.0. Klasa XslCompiledTransform jest nowym procesorem XSLT. Aby uzyskać więcej informacji, zobacz Using the XslCompiledTransform Class (Używanie klasy XslCompiledTransform) i Migrating From the XslTransform Class (Migrowanie z klasy XslTransform).

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest dopasowywany do elementów zdefiniowanych xsl:param w arkuszu stylów. Opcje przekształcania mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli bieżący węzeł jest ustawiony w drzewie węzła innym niż węzeł główny dokumentu, nie uniemożliwia to procesowi przekształcania uzyskiwania dostępu do wszystkich węzłów w załadowanym dokumencie. Po wykonaniu przekształcenia pozostaje XPathNavigator w jego pierwotnym stanie. Oznacza to, że węzeł, który jest bieżący przed procesem przekształcania, pozostaje bieżącym węzłem po wywołaniu Transform metody.

Ponieważ XmlReader zapewnia dane wyjściowe tylko do odczytu, xsl:output element jest ignorowany. Aby uzyskać więcej informacji, zobacz Outputs from an XslTransform (Dane wyjściowe z elementu XslTransform ).

Ta metoda umożliwia wykonywanie asynchronicznej transformacji dokumentu źródłowego.

Uwaga

Ta metoda jest przestarzała. Ustawienie XmlResolver właściwości określa sposób rozpoznawania funkcji document() XSLT. Zalecaną praktyką jest użycie metody , która przyjmuje Transform XmlResolver obiekt jako jeden z jego argumentów.

Zobacz też

Dotyczy

Transform(IXPathNavigable, XsltArgumentList)

Przestroga

You should pass XmlResolver to Transform() method

Przekształca dane XML w obiekcie IXPathNavigable przy użyciu określonej args wartości i zwraca wynik do .XmlReader

public:
 System::Xml::XmlReader ^ Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ args);
public System.Xml.XmlReader Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? args);
public System.Xml.XmlReader Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args);
[System.Obsolete("You should pass XmlResolver to Transform() method")]
public System.Xml.XmlReader Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList -> System.Xml.XmlReader
[<System.Obsolete("You should pass XmlResolver to Transform() method")>]
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList -> System.Xml.XmlReader
Public Function Transform (input As IXPathNavigable, args As XsltArgumentList) As XmlReader

Parametry

input
IXPathNavigable

Obiekt implementuje IXPathNavigable interfejs. W .NET Framework może to być element XmlNode (zazwyczaj XmlDocument) lub XPathDocument zawierający dane do przekształcenia.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe przekształcenia.

Zwraca

XmlReader

Element XmlReader zawierający wyniki przekształcenia.

Atrybuty

Uwagi

Uwaga

Klasa XslTransform jest przestarzała w .NET Framework w wersji 2.0. Klasa XslCompiledTransform jest nowym procesorem XSLT. Aby uzyskać więcej informacji, zobacz Using the XslCompiledTransform Class (Używanie klasy XslCompiledTransform) i Migrating From the XslTransform Class (Migrowanie z klasy XslTransform).

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Uwaga

Ta metoda jest teraz przestarzała. Ustawienie XmlResolver właściwości określa sposób rozpoznawania funkcji XSLT document() . Zalecaną praktyką jest użycie metody , która przyjmuje Transform XmlResolver obiekt jako jeden z jego argumentów.

Element args jest dopasowywany do elementów zdefiniowanych xsl:param w arkuszu stylów. Element xsl:output nie jest obsługiwany podczas wyprowadzania do elementu XmlReader ( xsl:output element jest ignorowany). Aby uzyskać więcej informacji, zobacz Outputs from an XslTransform (Dane wyjściowe z elementu XslTransform ).

Ta metoda umożliwia wykonywanie asynchronicznej transformacji dokumentu źródłowego.

Przekształcenia mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli przekazujesz węzeł inny niż węzeł główny dokumentu, nie uniemożliwia to procesowi przekształcania uzyskiwania dostępu do wszystkich węzłów w załadowanym dokumencie. Aby przekształcić fragment węzła, należy utworzyć XmlDocument obiekt zawierający tylko fragment węzła i przekazać go XmlDocument do Transform metody .

Poniższy przykład wykonuje przekształcenie na fragmentie węzła.

XslTransform xslt = new XslTransform();       
xslt.Load("print_root.xsl");  
XmlDocument doc = new XmlDocument();  
doc.Load("library.xml");  
// Create a new document containing just the node fragment.  
XmlNode testNode = doc.DocumentElement.FirstChild;   
XmlDocument tmpDoc = new XmlDocument();   
tmpDoc.LoadXml(testNode.OuterXml);  
// Pass the document containing the node fragment   
// to the Transform method.  
Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");  
xslt.Transform(tmpDoc, null, Console.Out);  

W przykładzie użyto library.xml plików i print_root.xsl jako danych wejściowych i wyjściowych w konsoli programu .

Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl   
Root node is book.  

library.xml

<library>  
  <book genre='novel' ISBN='1-861001-57-5'>  
     <title>Pride And Prejudice</title>  
  </book>  
  <book genre='novel' ISBN='1-81920-21-2'>  
     <title>Hook</title>  
  </book>  
</library>  

print_root.xsl

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" >  
  <output method="text" />   
  <template match="/">  
     Root node is  <value-of select="local-name(//*[position() = 1])" />   
  </template>  
</stylesheet>  

Zobacz też

Dotyczy

Transform(String, String)

Przestroga

You should pass XmlResolver to Transform() method

Przekształca dane XML w pliku wejściowym i zwraca wynik do pliku wyjściowego.

public:
 void Transform(System::String ^ inputfile, System::String ^ outputfile);
public void Transform (string inputfile, string outputfile);
[System.Obsolete("You should pass XmlResolver to Transform() method")]
public void Transform (string inputfile, string outputfile);
member this.Transform : string * string -> unit
[<System.Obsolete("You should pass XmlResolver to Transform() method")>]
member this.Transform : string * string -> unit
Public Sub Transform (inputfile As String, outputfile As String)

Parametry

inputfile
String

Adres URL dokumentu źródłowego, który ma zostać przekształcony.

outputfile
String

Adres URL pliku wyjściowego.

Atrybuty

Przykłady

Poniższy przykład przekształca books.xml plik przy użyciu output.xsl arkusza stylów i zwraca wyniki do books.html pliku.

// Create the XslTransform object.
XslTransform^ xslt = gcnew XslTransform;

// Load the stylesheet.
xslt->Load( "output.xsl" );

// Transform the file.
xslt->Transform("books.xml","books.html");
//Create the XslTransform object.
XslTransform xslt = new XslTransform();

//Load the stylesheet.
xslt.Load("output.xsl");

//Transform the file.
xslt.Transform("books.xml", "books.html");
'Create the XslTransform object.
Dim xslt as XslTransform = new XslTransform()

'Load the stylesheet.
xslt.Load("output.xsl")

'Transform the file.
xslt.Transform("books.xml", "books.html")

W przykładzie użyto następujących dwóch plików wejściowych:

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>

Uwagi

Uwaga

Klasa XslTransform jest przestarzała w .NET Framework w wersji 2.0. Klasa XslCompiledTransform jest nowym procesorem XSLT. Aby uzyskać więcej informacji, zobacz Using the XslCompiledTransform Class (Używanie klasy XslCompiledTransform) i Migrating From the XslTransform Class (Migrowanie z klasy XslTransform).

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Uwaga

Ta metoda jest przestarzała w wersji 1.1 .NET Framework. Ustawienie XmlResolver właściwości określa sposób rozpoznawania funkcji XSLT document() . Zalecaną praktyką jest użycie metody , która przyjmuje Transform XmlResolver obiekt jako jeden z jego argumentów.

Zobacz też

Dotyczy

Transform(XPathNavigator, XsltArgumentList, Stream)

Przestroga

You should pass XmlResolver to Transform() method

Przekształca dane XML w elemecie XPathNavigator przy użyciu określonej wartości args i generuje wynik na wartość Stream.

public:
 void Transform(System::Xml::XPath::XPathNavigator ^ input, System::Xml::Xsl::XsltArgumentList ^ args, System::IO::Stream ^ output);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList? args, System.IO.Stream output);
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.IO.Stream output);
[System.Obsolete("You should pass XmlResolver to Transform() method")]
public void Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.IO.Stream output);
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
[<System.Obsolete("You should pass XmlResolver to Transform() method")>]
member this.Transform : System.Xml.XPath.XPathNavigator * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
Public Sub Transform (input As XPathNavigator, args As XsltArgumentList, output As Stream)

Parametry

input
XPathNavigator

Element XPathNavigator zawierający dane, które mają zostać przekształcone.

args
XsltArgumentList

Argumenty XsltArgumentList kwalifikowane przestrzeni nazw używane jako dane wejściowe do transformacji.

output
Stream

Strumień, do którego chcesz uzyskać dane wyjściowe.

Atrybuty

Wyjątki

Wystąpił błąd podczas przetwarzania przekształcenia XSLT.

Uwaga: jest to zmiana zachowania z wcześniejszych wersji. Element XsltException jest zgłaszany, jeśli używasz programu Microsoft .NET Framework w wersji 1.1 lub starszej.

Uwagi

XslTransform obsługuje składnię XSLT 1.0. Arkusz stylów XSLT musi zawierać deklarację xmlns:xsl= http://www.w3.org/1999/XSL/Transformprzestrzeni nazw .

Element args jest zgodny z elementami zdefiniowanymi xsl:param w arkuszu stylów. Opcje przekształcania mają zastosowanie do dokumentu jako całości. Innymi słowy, jeśli bieżący węzeł jest ustawiony w drzewie węzła innym niż węzeł główny dokumentu, nie uniemożliwia to procesu przekształcania dostępu do wszystkich węzłów w załadowanym dokumencie. Po wykonaniu XPathNavigator transformacji pozostaje w oryginalnym stanie. Oznacza to, że węzeł, który jest bieżący przed procesem przekształcania, pozostaje bieżącym węzłem po Transform wywołaniu metody.

Zobacz Dane wyjściowe z elementu XslTransform , aby uzyskać szczegółowe informacje o obsługiwanych xsl:output atrybutach.

Uwaga

Ta metoda jest teraz przestarzała. Ustawienie XmlResolver właściwości określa sposób rozpoznawania funkcji XSLT document() . Zalecaną praktyką jest użycie Transform metody, która przyjmuje XmlResolver obiekt jako jeden z jego argumentów.

Zobacz też

Dotyczy