XmlDataSource.TransformFile プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
XmlDataSource コントロールによって管理される XML データに対して実行する XSLT 変換を定義する拡張スタイルシート言語 (XSL) ファイル (.xsl) のファイル名を指定します。
public:
virtual property System::String ^ TransformFile { System::String ^ get(); void set(System::String ^ value); };
public virtual string TransformFile { get; set; }
member this.TransformFile : string with get, set
Public Overridable Property TransformFile As String
プロパティ値
DataプロパティまたはDataFileプロパティに含まれるデータに対して実行する XML 変換を定義する XSL スタイル シート ファイルの絶対物理パスまたは相対パス。 既定値は Empty です。
例外
ドキュメントが読み込まれています。
例
次のコード例では、 XmlDataSource コントロールと TreeView コントロールを使用して、変換された XML データを Web フォームに表示する方法を示します。 変換は、 TransformFile プロパティで示されるスタイル シートを使用して実行されます。 必要に応じて、 XsltArgumentListを使用してスタイル シートの変換引数を指定できます。 詳細については、 TransformArgumentList プロパティを参照してください。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:XmlDataSource
id="XmlDataSource1"
runat="server"
datafile="bookstore.xml"
transformfile="bookstore.xsl"/>
<!- TreeView uses hierachical data, so the
XmlDataSource uses an XmlHierarchicalDataSourceView
when a TreeView is bound to it. -->
<asp:treeview
id="TreeView1"
runat="server"
datasourceid="XmlDataSource1">
<databindings>
<asp:treenodebinding depth="1" datamember="genre"
textfield="name" valuefield="name"/>
<asp:treenodebinding depth="2" datamember="book"
textfield="title" valuefield="ISBN"/>
<asp:treenodebinding depth="3" datamember="chapter"
textfield="name" valuefield="num"/>
</databindings>
</asp:treeview>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:xmldatasource
id="XmlDataSource1"
runat="server"
datafile="bookstore.xml"
transformfile="bookstore.xsl"/>
<!- TreeView uses hierachical data, so the
XmlDataSource uses an XmlHierarchicalDataSourceView
when a TreeView is bound to it. -->
<asp:treeview
id="TreeView1"
runat="server"
datasourceid="XmlDataSource1">
<databindings>
<asp:treenodebinding depth="1" datamember="genre"
textfield="name" valuefield="name"/>
<asp:treenodebinding depth="2" datamember="book"
textfield="title" valuefield="ISBN"/>
<asp:treenodebinding depth="3" datamember="chapter"
textfield="name" valuefield="num"/>
</databindings>
</asp:treeview>
</form>
</body>
</html>
コード例の XML ファイルには、次のデータがあります。
<bookstore>
<genre name="fiction">
<book ISBN="0000000000">
<title>Secrets of Silicon Valley</title>
<price>12.95</price>
<chapters>
<chapter num="1" name="Introduction" />
<chapter num="2" name="Body" />
<chapter num="3" name="Conclusion" />
</chapters>
</book>
</genre>
<genre name="novel">
<book genre="novel" ISBN="1111111111">
<title>Straight Talk About Computers</title>
<price>24.95</price>
<chapters>
<chapter num="1" name="Introduction" />
<chapter num="2" name="Body" />
<chapter num="3" name="Conclusion" />
</chapters>
</book>
</genre>
</bookstore>
XML 変換を実行する XSL スタイル シートの構造は次のとおりです。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="bookstore">
<bookstore>
<xsl:apply-templates select="genre"/>
</bookstore>
</xsl:template>
<xsl:template match="genre">
<genre>
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:apply-templates select="book"/>
</genre>
</xsl:template>
<xsl:template match="book">
<book>
<xsl:attribute name="ISBN">
<xsl:value-of select="@ISBN"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="title"/>
</xsl:attribute>
<xsl:attribute name="price">
<xsl:value-of select="price"/>
</xsl:attribute>
<xsl:apply-templates select="chapters/chapter" />
</book>
</xsl:template>
<xsl:template match="chapter">
<chapter>
<xsl:attribute name="num">
<xsl:value-of select="@num"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:apply-templates/>
</chapter>
</xsl:template>
</xsl:stylesheet>
注釈
TransformFileプロパティとTransform プロパティの両方が設定されている場合、TransformFile プロパティが優先され、Transform プロパティで指定されたスタイル シート要素の代わりに XSL スタイル シート ファイル (.xsl) 内のデータが使用されます。 XPath 式が XPath プロパティを使用して設定されている場合は、XML データの変換後に適用されます。
Transform プロパティの値を変更すると、DataSourceChanged イベントが発生します。 キャッシュが有効になっていて、 Transformの値を変更すると、キャッシュは無効になります。
Note
XmlDataSource クラスは、非推奨の XslTransform クラスを使用して XSL 変換を実行します。 XslTransform クラスが非推奨になった後に導入されたスタイル シート機能を使用する場合は、XslCompiledTransform クラスを使用して変換を手動で適用します。