URL で指定された XSLT スタイル シートを読み込みます。
Overloads Public Sub Load( _
ByVal url As String _)
[C#]
public void Load(stringurl);
[C++]
public: void Load(String* url);
[JScript]
public function Load(
url : String);
パラメータ
- url
読み込む XSLT スタイル シートを指定する URL。
例外
| 例外の種類 | 条件 |
|---|---|
| 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 に必要な資格情報を指定してください。
スタイルシートに埋め込みスクリプトが含まれている場合、スクリプトはアセンブリにコンパイルされます。スタイルシートの URI は、アセンブリに適用する証拠を作成するときに使用します。
メモ 呼び出し元が UnmanagedCode アクセス許可を持っていない場合、埋め込みスクリプトはコンパイルされません。また SecurityException がスローされます。詳細については、 SecurityPermissionFlag.UnmanagedCode および SecurityPermission のトピックを参照してください。
使用例
[Visual Basic, C#, C++] XML ドキュメントを HTML ドキュメントに変換する例を次に示します。ここでは、表内の各書籍の ISBN、タイトル、および価格を表示します。
Option Strict
Option Explicit
Imports System
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 'Main
End Class 'Sample
[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 = "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();
}
}
[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"output.xsl";
//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, 0, writer, 0);
writer->Close();
}
[Visual Basic, C#, C++] このサンプルでは、次の 2 つの入力ファイルを使用します。
[Visual Basic, C#, C++] 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>
[Visual Basic, C#, C++] 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>
[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 オーバーロードの一覧