XslTransformとは? わかりやすく解説

XslTransform クラス

メモ : このクラスは、互換性のために残されています。

XSLT (Extensible Stylesheet Language Transformations) スタイル シートを使用して XML データを変換します。

名前空間: System.Xml.Xsl
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

<ObsoleteAttribute("This class has been deprecated. Please
 use System.Xml.Xsl.XslCompiledTransform instead. http://go.microsoft.com/fwlink/?linkid=14202")>
 _
Public NotInheritable Class
 XslTransform
[ObsoleteAttribute("This class has been deprecated. Please
 use System.Xml.Xsl.XslCompiledTransform instead. http://go.microsoft.com/fwlink/?linkid=14202")]
 
public sealed class XslTransform
[ObsoleteAttribute(L"This class has been deprecated. Please
 use System.Xml.Xsl.XslCompiledTransform instead. http://go.microsoft.com/fwlink/?linkid=14202")]
 
public ref class XslTransform sealed
/** @attribute ObsoleteAttribute("This class has been deprecated.
 Please use System.Xml.Xsl.XslCompiledTransform instead. http://go.microsoft.com/fwlink/?linkid=14202")
 */ 
public final class XslTransform
ObsoleteAttribute("This class has been deprecated. Please
 use System.Xml.Xsl.XslCompiledTransform instead. http://go.microsoft.com/fwlink/?linkid=14202")
 
public final class XslTransform
解説解説
メモメモ

XslTransform クラスは、Microsoft .NET Framework Version 2.0 では使用されなくなりました。XslCompiledTransform クラスは、新しい XSLT プロセッサです。詳細については、XslCompiledTransform クラスの使用、XslTransform クラスからの移行 の各トピックを参照してください。

XslTransform は、XSLT 1.0 構文をサポートしています。XSLT スタイル シートでは、名前空間 http://www.w3.org/1999/XSL/Transform を使用する必要があります。

XsltArgumentList クラスを使用して、引数をスタイル シートに追加することもできます。このクラスには、スタイル シートの入力パラメータと、スタイル シートから呼び出すことができる拡張機能オブジェクトが含まれています。

XML データを変換するには、次を実行します。

  1. XslTransform オブジェクトを作成します。

  2. Load メソッドを使用して、変換用のスタイル シートを読み込みます。このメソッドは複数のオーバーロードを持ち、XmlReader、XPathNavigator、IXPathNavigable、またはファイル位置を含む URL を使用して、スタイル シートを読み込むことができます。

  3. Transform メソッドを使用して、XML データを変換します。このメソッドはオーバーロードを持ち、異なる型の入出力を処理できます。追加の引数を含む XsltArgumentList を指定して、変換中に入力として使用することもできます。

セキュリティについての考慮事項

XslTransform クラスを使用するアプリケーションを作成する場合は、次の項目とその影響に注意してください。

これらのセキュリティの問題は、信頼できないソースからの XslTransform オブジェクト、XSLT スタイル シート、または XML ソース データを受け入れないことで軽減できます。

スクリプトのサポート

このクラスは、msxsl:script 要素を使用して埋め込まれたスクリプトをサポートします。

.NET Framework Version 1.1 では、スタイル シートの証拠によって、埋め込みスクリプトに与えられるアクセス許可が決まります。

信頼度の低い呼び出し元の場合 : 埋め込みスクリプトをコンパイルするには UnmanagedCode アクセス許可が必要です。Load メソッドで Evidence を指定するには ControlEvidence アクセス許可が必要です。必要なアクセス許可が呼び出し元にない場合は SecurityException がスローされます。詳細については、System.Security.Permissions.SecurityPermission と System.Security.Permissions.SecurityPermissionFlag のトピックを参照してください。

msxsl:script 要素には次の要件があります。

Note スクリプト ブロックを CDATA セクションにラップすることをお勧めします。

 <msxsl:script implements-prefix='xy' language='C#'>
   <![CDATA[
   // Add code here.
   ]]>
 </msxsl:script>

関数は、msxsl:script 要素内で宣言できます。既定でサポートされる名前空間を次の表に示します。

スクリプト関数で定義された、提供される引数と戻り値は、次に示す W3C (World Wide Web Consortium) 仕様の型のいずれかである必要があります。W3C 仕様の型 (XPath または XSLT のいずれか) と、対応する .NET Framework クラス間のマップの詳細を次の表に示します。

W3C 仕様の型

等価な .NET クラス

文字列 (XPath)

System.String

ブール値 (XPath)

System.Boolean

数値 (XPath)

System.Double

結果木素片 (XSLT)

System.Xml.XPath.XPathNavigator

ノード集合 (XPath)

System.Xml.XPath.XPathNodeIterator

スクリプト関数で、Int16、UInt16、Int32、UInt32、Int64、UInt64、単精度浮動小数点型、または 10 進のいずれかの数値型が使用されている場合、これらの型は強制的に倍精度浮動小数点型に変換され、W3C XPath 型の数値に割り当てられます。

引数の結果を必要な型に変換できない関数が呼び出されると、例外がスローされます。

メモメモ

msxsl:script と msxsl:node-list は、urn:schemas-microsoft-com:xslt 名前空間の唯一の関数で、XslTransform クラスによってサポートされます。

XslTransform には、拡張機構として共通言語ランタイム (CLR) コードを利用する機能が用意されています。これは、クラスのインスタンスを XslTransform クラスに渡して、そのパブリック メソッドを XSLT スタイル シート内で呼び出すことによって実行されます。params キーワードを使用すると、数を指定せずにパラメータを渡すことができますが、このキーワードで定義されるメソッドはこのシナリオでは正しく動作しません。詳細については、params (C# リファレンス) のトピックを参照してください。

詳細については、「XslTransform クラスを使用した XSLT 変換」を参照してください。

使用例使用例

指定した XML ドキュメントを変換し、その結果をコンソールに出力する例を次に示します。

'Create a new XslTransform object.
Dim xslt As New XslTransform()

'Load the stylesheet.
xslt.Load(CType("http://server/favorite.xsl", String))

'Create a new XPathDocument and load the XML data to be transformed.
Dim mydata As New XPathDocument("inputdata.xml")

'Create an XmlTextWriter which outputs to the console.
Dim writer As New XmlTextWriter(Console.Out)

'Transform the data and send the output to the console.
xslt.Transform(mydata, Nothing, writer, Nothing)
//Create a new XslTransform object.
XslTransform xslt = new XslTransform();

//Load the stylesheet.
xslt.Load("http://server/favorite.xsl");

//Create a new XPathDocument and load the XML data to be transformed.
XPathDocument mydata = new XPathDocument("inputdata.xml");

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

//Transform the data and send the output to the console.
xslt.Transform(mydata,null,writer, null);
//Create a new XslTransform object.
XslTransform^ xslt = gcnew XslTransform;

//Load the stylesheet.
xslt->Load( "http://server/favorite.xsl" );

//Create a new XPathDocument and load the XML data to be transformed.
XPathDocument^ mydata = gcnew XPathDocument( "inputdata.xml" );

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

//Transform the data and send the output to the console.
xslt->Transform^(mydata,0,writer,0);
//Create a new XslTransform object.
XslTransform xslt = new XslTransform();

//Load the stylesheet.
xslt.Load("http://server/favorite.xsl");

//Create a new XPathDocument and load the XML data to be transformed.
XPathDocument myData = new XPathDocument("inputdata.xml");

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

//Transform the data and send the output to the console.
xslt.Transform(myData, null, writer, null);
継承階層継承階層
System.Object
  System.Xml.Xsl.XslTransform
スレッド セーフスレッド セーフ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XslTransform メンバ
System.Xml.Xsl 名前空間

XslTransform コンストラクタ


XslTransform プロパティ


XslTransform メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XslTransform クラス
System.Xml.Xsl 名前空間

XslTransform メンバ

XSLT (Extensible Stylesheet Language Transformations) スタイル シートを使用して XML データを変換します。

XslTransform データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド XslTransform XslTransform クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XslTransform クラス
System.Xml.Xsl 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「XslTransform」の関連用語

XslTransformのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XslTransformのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS