This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The removeParameter() method of the XSLTProcessor interface removes the parameter (<xsl:param>) and its value from the stylesheet imported in the processor.
removeParameter(namespaceURI, localName)
namespaceURIThe namespace associated with the parameter name. A "null" value is treated the same as the empty string ("").
localNameThe name of the parameter in the associated namespace.
None (undefined).
First, the showItems parameter is set to "yes", which allows the list items to be displayed in the output.
After that, the showItems parameter is removed using removeParameter(), and the transformation is performed again, resulting in no items being displayed.
<div id="result"></div>
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> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
removeParameter |
1 | 12 | 1 | ≤12.1 | 3.1 | 18 | 4 | ≤12.1 | 2 | 1.0 | 3 | 2 |
XSLTProcessor.getParameter()XSLTProcessor.setParameter()XSLTProcessor.clearParameters()XSLTProcessor.reset()
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XSLTProcessor/removeParameter