| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/XSLTProcessor/clearParameters | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The clearParameters() method of the XSLTProcessor interface removes all parameters (<xsl:param>) and their values from the stylesheet imported in the processor. The XSLTProcessor will then use the default values specified in the XSLT stylesheet.
clearParameters()
None.
None (undefined).
This example shows how clearParameters() can be used to reset all parameters back to their default values as specified in the XSLT stylesheet.
<div id="result"></div>
const xmlString = `
<items>
<item>Item 1</item>
<item>Item 2</item>
<item>Item 3</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 the 'showItems' parameter to 'no' and perform the first transformation
xsltProcessor.setParameter(null, "showItems", "no");
let resultFragment = xsltProcessor.transformToFragment(xmlDoc, document);
document.getElementById("result").appendChild(resultFragment);
// Add a horizontal rule to separate the results
document.getElementById("result").appendChild(document.createElement("hr"));
// Clear all parameters, resetting 'showItems' to its default value ('yes')
xsltProcessor.clearParameters();
resultFragment = xsltProcessor.transformToFragment(xmlDoc, document);
document.getElementById("result").appendChild(resultFragment);
| Specification |
|---|
| DOM # dom-xsltprocessor-clearparameters |
XSLTProcessor.getParameter()XSLTProcessor.setParameter()XSLTProcessor.removeParameter()XSLTProcessor.reset()This page was last modified on Oct 13, 2025 by MDN contributors.
XSLTProcessorAbortControllerAbortSignalAbstractRangeAttrCDATASectionCharacterDataCommentCustomEventDOMErrorDOMExceptionDOMImplementationDOMParserDOMTokenListDocumentDocumentFragmentDocumentTypeElementEventEventTargetHTMLCollectionMutationObserverMutationRecordNamedNodeMapNodeNodeIteratorNodeListProcessingInstructionQuotaExceededErrorRangeShadowRootStaticRangeTextTreeWalkerXMLDocumentXPathEvaluatorXPathExpressionXPathResultYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |