XSLTProcessor: importStylesheet() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
importStylesheet()
は XSLTProcessor
インターフェイスのメソッドで、プロセッサーに XSLT スタイルシートをインポートします。
構文
js
importStylesheet(style)
引数
返値
なし (undefined
)。
例
importStylesheet() の使用
この例では、 XML データの変換に使用するために、 importStylesheet()
が XSLT スタイルシートを XSLTProcessor
に読み込むことを示しています。
HTML
html
<div id="result"></div>
JavaScript
js
const xmlString = `
<items>
<item>Item 1</item>
<item>Item 2</item>
</items>
`;
const xsltString = `
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<ul>
<xsl:for-each select="items/item">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
`;
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlString, "application/xml");
const xsltDoc = parser.parseFromString(xsltString, "application/xml");
const xsltProcessor = new XSLTProcessor();
// Import the XSLT stylesheet into the XSLTProcessor
xsltProcessor.importStylesheet(xsltDoc);
// Perform the transformation from XML to HTML
const resultFragment = xsltProcessor.transformToFragment(xmlDoc, document);
// Display the transformed result in the page
document.getElementById("result").appendChild(resultFragment);
結果
仕様書
Specification |
---|
DOM # dom-xsltprocessor-importstylesheet |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
importStylesheet |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.