メモ : このメンバは旧バージョン用です。
証拠を Load() メソッドに渡す必要があります。
XmlReader に含まれる XSLT スタイルシートを読み込みます。
<Obsolete("You should pass evidence to Load() method", False)>
Overloads Public Sub Load( _ ByVal stylesheet As XmlReader _)
[C#]
[Obsolete("You should pass evidence to Load() method", false)]
public void Load(XmlReaderstylesheet);
[C++]
[Obsolete("You should pass evidence to Load() method", false)]
public: void Load(XmlReader* stylesheet);
[JScript]
public
Obsolete("You should pass evidence to Load() method", false)
function Load(stylesheet : XmlReader);
パラメータ
- stylesheet
XSLT スタイル シートを格納している XmlReader オブジェクト。
例外
例外の種類 | 条件 |
---|---|
XsltCompileException | 現在のノードは、有効なスタイル シートに準拠していません。 |
SecurityException | スタイルシートに埋め込みスクリプトが含まれており、読み出し元に UnmanagedCode アクセス許可がありません。 |
解説
XslTransform は、XSLT 1.0 構文をサポートしています。XSLT スタイル シートには、名前空間宣言 xmlns:xsl= http://www.w3.org/1999/XSL/Transform を含める必要があります。
このメソッドは、 xsl:include 要素および xsl:import 要素で参照される任意のスタイル シートを含む XSLT スタイル シートを読み込みます。外部リソースが、ユーザー資格情報を持たない XmlUrlResolver で解決されました。認証を要求するネットワーク リソース上にスタイルシートがある場合は、引数の 1 つとして XmlResolver を受け取るオーバーロードを使用し、 XmlResolver に必要な資格情報を指定してください。
スタイル シートは、 XmlReader の現在のノードから、すべての子を通じて読み込まれます。これにより、ドキュメントの一部をスタイル シートとして使用できます。 Load メソッドが返されると、 XmlReader は、スタイル シートの末尾の後の次のノードに配置されます。ドキュメントの末尾に達すると、 XmlReader は、ファイルの末尾 (EOF) に配置されます。
スタイル シートにエンティティが含まれている場合は、エンティティを解決できる XmlReader を指定する必要があります。 XmlReader.CanResolveEntity は true を返します。この場合は、 XmlValidatingReader を使用できます。
メモ このメソッドは、Microsoft .NET Framework Version 1.1 以降では使用しません。引数の 1 つとして System.Security.Policy.Evidence オブジェクトを受け取る Load オーバーロードを使用して証拠を提供することをお勧めします。このメソッドを使用する場合、埋め込みスクリプトを含んでいるスタイルシートは次の方法で処理されます。スタイルシートに埋め込みスクリプトが含まれている場合、スクリプトはアセンブリにコンパイルされます。アセンブリは完全に信頼されています。呼び出し元が UnmanagedCode アクセス許可を持っていない場合、埋め込みスクリプトはコンパイルされません。また SecurityException がスローされます。詳細については、 SecurityPermissionFlag.UnmanagedCode および SecurityPermission のトピックを参照してください。
使用例
[Visual Basic, C#, C++] すべての書籍をタイトル順に並べ替える XML ファイル変換の例を次に示します。
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath
public class Sample
private const filename as String = "books.xml"
private const stylesheet as String = "titles.xsl"
public shared sub Main()
'Create the reader to load the stylesheet.
'Move the reader to the xsl:stylesheet node.
Dim reader as XmlTextReader = new XmlTextReader(stylesheet)
reader.Read()
reader.Read()
'Create the XslTransform object and load the stylesheet.
Dim xslt as XslTransform = new XslTransform()
xslt.Load(reader)
'Load the file to transform.
Dim doc as XPathDocument = new XPathDocument(filename)
'Create an XmlTextWriter which outputs to the console.
Dim writer as XmlTextWriter = new XmlTextWriter(Console.Out)
'Transform the file and send the output to the console.
xslt.Transform(doc, nothing, writer)
writer.Close()
end sub
end class
[C#]
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 = "titles.xsl";
public static void Main()
{
//Create the reader to load the stylesheet.
//Move the reader to the xsl:stylesheet node.
XmlTextReader reader = new XmlTextReader(stylesheet);
reader.Read();
reader.Read();
//Create the XslTransform object and load the stylesheet.
XslTransform xslt = new XslTransform();
xslt.Load(reader);
//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);
writer.Close();
}
}
[C++]
#using <mscorlib.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 = S"books.xml";
String * stylesheet = S"titles.xsl";
// Create the reader to load the stylesheet.
// Move the reader to the xsl:stylesheet node.
XmlTextReader* reader = new XmlTextReader(stylesheet);
reader -> Read();
reader -> Read();
// Create the XslTransform object and load the stylesheet.
XslTransform* xslt = new XslTransform();
xslt -> Load(reader);
// 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, 0, writer);
writer -> Close();
}
[Visual Basic, C#, C++] この例では、次のデータ ファイルを入力として使用しています。
[Visual Basic, C#, C++] books.xml
<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>
[Visual Basic, C#, C++] titles.xsl
<!--Stylesheet to sort all books by title-->
<!--Created 2/13/2001-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="bookstore">
<books>
<xsl:apply-templates select="book">
<xsl:sort select="title"/>
</xsl:apply-templates>
</books>
</xsl:template>
<xsl:template match="book">
<book><xsl:copy-of select="node()"/></book>
</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.Load オーバーロードの一覧