URL で指定された XSLT スタイル シートを読み込みます。
Overloads Public Sub Load( _
ByVal url As String, _ ByVal resolver As XmlResolver _)
[C#]
public void Load(stringurl,XmlResolverresolver);
[C++]
public: void Load(String* url,XmlResolver* resolver);
[JScript]
public function Load(
url : String,resolver : XmlResolver);
パラメータ
url
読み込む XSLT スタイル シートを指定する URL。resolver
該当するスタイル シート、および xsl:import 要素と xsl:include 要素で参照される任意のスタイル シートを読み込むために使用される XmlResolver 。これが null 参照 (Visual Basic では Nothing) の場合は、ユーザー資格情報を持たない既定の XmlUrlResolver がスタイルシートを開くときに使用されます。既定の XmlUrlResolver は、スタイルシート内の外部リソースの解決には使用されないため、 xsl:import 要素と xsl:include 要素は解決されません。
Load メソッドが完了した後、 XmlResolver がキャッシュされていません。
例外
例外の種類 | 条件 |
---|---|
XsltCompileException | 読み込まれたリソースが、有効なスタイル シートではありません。 |
SecurityException | スタイルシートに埋め込みスクリプトが含まれており、呼び出し元に UnmanagedCode アクセス許可がありません。 |
解説
XslTransform は、XSLT 1.0 構文をサポートしています。XSLT スタイル シートには、名前空間宣言 xmlns:xsl= http://www.w3.org/1999/XSL/Transform を含める必要があります。
スタイルシートに埋め込みスクリプトが含まれている場合、スクリプトはアセンブリにコンパイルされます。スタイルシートの URI は、アセンブリに適用する証拠を作成するときに使用します。
メモ 呼び出し元が UnmanagedCode アクセス許可を持っていない場合、埋め込みスクリプトはコンパイルされません。また SecurityException がスローされます。詳細については、 SecurityPermissionFlag.UnmanagedCode および SecurityPermission のトピックを参照してください。
使用例
[Visual Basic, C#, C++] XML ドキュメントを HTML ドキュメントに変換する例を次に示します。別のスタイル シートを参照する xsl:include 要素を含む XSLT スタイル シートを読み込む例を次に示します。 XmlUrlResolver は、含まれるスタイル シートのネットワーク リソースにアクセスするために必要な資格情報を設定する Load メソッドに渡されます。
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports System.Net
public class Sample
private shared filename as String = "books.xml"
private shared stylesheet as String = "sort.xsl"
public shared sub Main()
'Create the XslTransform.
Dim xslt as XslTransform = new XslTransform()
'Create a resolver and set the credentials to use.
Dim resolver as XmlUrlResolver = new XmlUrlResolver()
resolver.Credentials = CredentialCache.DefaultCredentials
'Load the stylesheet.
xslt.Load(stylesheet, resolver)
'Load the XML data file.
Dim doc as XPathDocument = new XPathDocument(filename)
'Create the XmlTextWriter to output to the console.
Dim writer as XmlTextWriter = new XmlTextWriter(Console.Out)
'Transform the file.
xslt.Transform(doc, nothing, writer, nothing)
writer.Close()
end sub
end class
[C#]
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Net;
public class Sample
{
private const String filename = "books.xml";
private const String stylesheet = "sort.xsl";
public static void Main()
{
//Create the XslTransform.
XslTransform xslt = new XslTransform();
//Create a resolver and set the credentials to use.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = CredentialCache.DefaultCredentials;
//Load the stylesheet.
xslt.Load(stylesheet, resolver);
//Load the XML data file.
XPathDocument doc = new XPathDocument(filename);
//Create the XmlTextWriter to output to the console.
XmlTextWriter writer = new XmlTextWriter(Console.Out);
//Transform the file.
xslt.Transform(doc, null, writer, null);
writer.Close();
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::XPath;
using namespace System::Xml::Xsl;
using namespace System::Net;
int main()
{
String * filename = S"books.xml";
String * stylesheet = S"sort.xsl";
// Create the XslTransform.
XslTransform* xslt = new XslTransform();
// Create a resolver and set the credentials to use.
XmlUrlResolver* resolver = new XmlUrlResolver();
resolver -> Credentials = CredentialCache::DefaultCredentials;
// Load the stylesheet.
xslt -> Load(stylesheet, resolver);
// Load the XML data file.
XPathDocument* doc = new XPathDocument(filename);
// Create the XmlTextWriter to output to the console.
XmlTextWriter* writer = new XmlTextWriter(Console::Out);
// Transform the file.
xslt -> Transform(doc, 0, writer, 0);
writer -> Close();
}
[Visual Basic, C#, C++] この例では、次のデータ ファイルを入力として使用しています。
[Visual Basic, C#, C++] books.xml
<!-- 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++] sort.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="bookstore"/>
<xsl:include href="http://serverA/includefile.xsl"/>
<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>
[Visual Basic, C#, C++] includefile.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">
<xsl:sort select="@ISBN"/>
</xsl:apply-templates>
</TABLE>
</BODY>
</HTML>
</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 オーバーロードの一覧 | XmlResolver.Credentials | CredentialCache | NetworkCredential | XmlSecureResolver