メモ : この名前空間、クラス、およびメンバは、.NET Framework Version 1.1 だけでサポートされています。
指定した args を使用して XPathNavigator の XML データを変換し、その結果を Stream に出力します。
Overloads Public Sub Transform( _
ByVal input As XPathNavigator, _ ByVal args As XsltArgumentList, _ ByVal output As Stream, _ ByVal resolver As XmlResolver _)
[C#]
public void Transform(XPathNavigatorinput,XsltArgumentListargs,Streamoutput,XmlResolverresolver);
[C++]
public: void Transform(XPathNavigator* input,XsltArgumentList* args,Stream* output,XmlResolver* resolver);
[JScript]
public function Transform(
input : XPathNavigator,args : XsltArgumentList,output : Stream,resolver : XmlResolver);
パラメータ
input
変換されるデータを含む XPathNavigator 。 Transform メソッドは、ドキュメント全体のコンテキストで動作し、ドキュメント全体を変換します。XML ドキュメントの一部を変換する方法については、「 XslTransform クラスによる XSLT プロセッサの実装 」を参照してください。args
変換に対する入力として使用された名前空間限定引数を含む XsltArgumentList 。output
出力先のストリーム。resolver
XSLT の document() 関数を解決するために使用する XmlResolver 。これが null 参照 (Visual Basic では Nothing) の場合、document() 関数は解決されません。Transform メソッドが完了した後、 XmlResolver がキャッシュされていません。
例外
例外の種類 | 条件 |
---|---|
XsltException | XSLT 変換の処理中にエラーが発生しました。 |
解説
XslTransform は、XSLT 1.0 構文をサポートしています。XSLT スタイル シートには、名前空間宣言 xmlns:xsl= http://www.w3.org/1999/XSL/Transform を含める必要があります。
args は、スタイル シートに定義されている xsl:param 要素と一致します。選択された変換は、ドキュメント全体に適用されます。つまり、現在のノードが、ドキュメント ルート ノード以外のノード ツリー上に設定されている場合、これによって、読み込まれたドキュメント内のすべてのノードに変換処理が行われることを防ぐことはできません。変換が行われた後も、 XPathNavigator は元の状態を維持します。これは現在のノードが、変換処理の前も Transform メソッドが呼び出された後も、現在のノードのままであることを示します。
どの xsl:output 属性がサポートされているかの詳細については、「 XslTransform からの出力 」を参照してください。
使用例
[Visual Basic, C#, C++] 顧客テーブルを XmlDataDocument に読み込み、XSLT 変換を実行して、顧客データを HTML テーブルに引き出す例を次に示します。この例では、SQL Server 2000 Northwind データベースを使用しています。
Imports System
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
[C#]
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);
}
}
[C++]
#using <mscorlib.dll>
#using <System.dll>
#using <System.Data.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Data;
using namespace System::Data::SqlClient;
using namespace System::Xml;
using namespace System::Xml::XPath;
using namespace System::Xml::Xsl;
int main()
{
// Create a DataSet and load it with customer data.
DataSet* dsNorthwind = new DataSet();
String* sConnect;
sConnect=S"Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind";
SqlConnection* nwconnect = new SqlConnection(sConnect);
String* sCommand = S"Select * from Customers where Region='WA'";
SqlDataAdapter* myDataAdapter = new SqlDataAdapter(sCommand, nwconnect);
myDataAdapter->Fill(dsNorthwind,S"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(S"customers.xsl");
// Create an XPathNavigator to use in the transform.
XPathNavigator* nav = doc->CreateNavigator();
// Create a FileStream object.
FileStream* fs = new FileStream(S"cust.html", FileMode::Create);
// Transform the data.
xsl->Transform(nav, 0, fs, 0);
}
この例では、入力として customers.xsl というファイルを使用しています。
<!-- 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>
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
XslTransform クラス | XslTransform メンバ | System.Xml.Xsl 名前空間 | XslTransform.Transform オーバーロードの一覧 | XsltArgumentList | XslTransform クラスの随意動作の実装 | XmlSecureResolver | XmlResolver.Credentials