XSLTProcessor: removeParameter() メソッド

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.

removeParameter()XSLTProcessor インターフェイスのメソッドで、このプロセッサーにインポートされたスタイルシートから、引数 (<xsl:param>) とその値を除去します。

構文

js
removeParameter(namespaceURI, localName)

引数

namespaceURI

引数名に関連付けられた名前空間。 "null" の値は空文字列 ("") と同様に扱われます。

localName

関連付けられた名前空間にある引数名。

返値

なし (undefined)。

removeParameter() を使用

最初の showItems引数を "yes" に設定すると、リストアイテムが出力先に表示されます。

その後、 showItems 引数は removeParameter() を使用して除去されてから、変換が再度実行されるため、アイテムは表示されません。

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:param name="showItems" select="'yes'"/>
  <xsl:template match="/">
    <!-- If showItems is 'yes', display the list of items -->
    <xsl:if test="$showItems = 'yes'">
      <ul>
        <xsl:for-each select="items/item">
          <li><xsl:value-of select="."/></li>
        </xsl:for-each>
      </ul>
    </xsl:if>
    <!-- If showItems is 'no', display a message -->
    <xsl:if test="$showItems = 'no'">
      <div>No content to show</div>
    </xsl:if>
  </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();
xsltProcessor.importStylesheet(xsltDoc);

// Set 'showItems' to 'no' and perform the first transformation
xsltProcessor.setParameter(null, "showItems", "no");
const resultContainer = document.getElementById("result");
let resultFragment = xsltProcessor.transformToFragment(xmlDoc, document);
resultContainer.appendChild(resultFragment);

// Add a horizontal rule to separate the results
resultContainer.appendChild(document.createElement("hr"));

// Remove the 'showItems' parameter, reverting it to the default value ('yes')
xsltProcessor.removeParameter(null, "showItems");
resultFragment = xsltProcessor.transformToFragment(xmlDoc, document);
resultContainer.appendChild(resultFragment);

結果

仕様書

Specification
DOM
# dom-xsltprocessor-removeparameter

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
removeParameter

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報