XSLTProcessor: removeParameter() Methode

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.

Die removeParameter()-Methode der XSLTProcessor-Schnittstelle entfernt den Parameter () und dessen Wert aus dem Stylesheet, das im Prozessor importiert wurde.

Syntax

js
removeParameter(namespaceURI, localName)

Parameter

namespaceURI

Der Namespace, der mit dem Parameternamen verknüpft ist. Ein "null"-Wert wird genauso behandelt wie der leere String ("").

localName

Der Name des Parameters im zugehörigen Namespace.

Rückgabewert

Keiner (undefined).

Beispiele

Verwendung von removeParameter()

Zuerst wird der showItems-Parameter auf "yes" gesetzt, was das Anzeigen der Listenelemente in der Ausgabe ermöglicht.

Danach wird der showItems-Parameter mit removeParameter() entfernt, und die Transformation wird erneut durchgeführt, wodurch keine Elemente angezeigt werden.

HTML

html

JavaScript

js
const xmlString = `

  Item 1
  Item 2

`;

const xsltString = `

  
  
    
    
      
No content to show
`; 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);

Ergebnis

Spezifikationen

Specification
DOM
# dom-xsltprocessor-removeparameter

Browser-Kompatibilität

Siehe auch