XslCompiledTransform 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用 XSLT 樣式表轉換 XML 資料。
public ref class XslCompiledTransform sealed
public sealed class XslCompiledTransform
type XslCompiledTransform = class
Public NotInheritable Class XslCompiledTransform
- 繼承
-
XslCompiledTransform
範例
以下範例執行一個轉換並輸出到檔案。
// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("output.xsl");
// Execute the transform and output the results to a file.
xslt.Transform("books.xml", "books.html");
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
' Execute the transform and output the results to a file.
xslt.Transform("books.xml", "books.html")
範例使用以下兩個輸入檔案:
<?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>
<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>
備註
欲了解更多關於此 API 的資訊,請參閱 XslCompiledTransform 的補充 API 備註。
建構函式
| 名稱 | Description |
|---|---|
| XslCompiledTransform() |
初始化 XslCompiledTransform 類別的新執行個體。 |
| XslCompiledTransform(Boolean) |
初始化一個新的類別實例 XslCompiledTransform ,並使用指定的除錯設定。 |
屬性
| 名稱 | Description |
|---|---|
| OutputSettings |
會取得 XmlWriterSettings 一個物件,包含從 |
| TemporaryFiles |
成功呼叫Load該方法後,會取得包含磁碟上暫存檔案的 。TempFileCollection |
方法
適用於
執行緒安全性
XslCompiledTransform物件一旦載入,便是執行緒安全的。 換句話說,方法成功完成後 Load ,可以同時從多個執行緒呼叫該 Transform 方法。
如果Load在另一個執行緒中再次呼叫該方法,XslCompiledTransform物件Transform則會Transform以繼續使用舊狀態完成呼叫。 當方法成功完成時 Load ,會使用新狀態。
當同時從多個執行緒呼叫時,此 Load 方法並不安全。