<!DOCTYPE HTML><html><head><title>Test for setParameter/getParameter</title><scriptsrc="/tests/SimpleTest/SimpleTest.js"></script><linkrel="stylesheet"type="text/css"href="/tests/SimpleTest/test.css"/></head><body><pid="display"></p><divid="content"style="display: none"><pid="number">123</p><pid="string">abc</p></div><preid="test"><script>letprocessor=newXSLTProcessor();processor.setParameter(null,"test","hello");is(processor.getParameter(null,"test"),"hello","null namespace works");processor.setParameter("foo","bar","foobar");is(processor.getParameter("foo","bar"),"foobar","non-null namespace works");processor.setParameter(null,"test",123);is(processor.getParameter(null,"test"),123,"number value works");processor.removeParameter(null,"test");is(processor.getParameter(null,"test"),null,"removeParameter works");is(processor.getParameter(null,"not-here"),null,"nonexistant parameter");letparser=newDOMParser();conststyle=`<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:exslt="http://exslt.org/common"> <xsl:output method="html" /> <xsl:param name="test" /> <xsl:template match="/"> <p id="result"><xsl:value-of select="exslt:object-type($test)" /></p> </xsl:template> </xsl:stylesheet>`;conststyleDoc=parser.parseFromString(style,"text/xml");constxml=`<root />`;constsourceDoc=parser.parseFromString(xml,"text/xml");functioncheckParameter(value,parameter){letvalueType=typeofvalue;switch(valueType){case"number":case"boolean":case"string":is(typeofparameter,valueType,"Parameter has right type");is(parameter,value,"Parameter has right value");return;case"object":if(valueinstanceofArray||valueinstanceofNodeList){ok(parameterinstanceofArray,"Parameter has right type");ok(parameter.length==value.length&¶meter.every((p,i)=>value[i]===p),"Parameter has right value");return;}if(valueinstanceofNode){is(parameter,value,"Parameter has right value");return;}if(valueinstanceofXPathResult){ok(parameterinstanceofXPathResult,"Parameter has right type");is(parameter.resultType,value.resultType,"Parameter has right inner type");letvalueProperty;switch(value.resultType){caseXPathResult.NUMBER_TYPE:valueProperty="numberValue";break;caseXPathResult.BOOLEAN_TYPE:valueProperty="booleanValue";break;caseXPathResult.STRING_TYPE:valueProperty="stringValue";break;caseXPathResult.FIRST_ORDERED_NODE_TYPE:valueProperty="singleNodeValue";break;default:ok(false,"Unexpected inner type");return;}is(parameter[valueProperty],value[valueProperty],"Parameter has right value");return;}}ok(false,"Unexpected value");}functiongetXSLTType(value){letvalueType=typeofvalue;switch(valueType){case"number":case"boolean":case"string":returnvalueType;case"object":if(valueinstanceofArray||valueinstanceofNode||valueinstanceofNodeList){return"node-set";}if(valueinstanceofXPathResult){switch(value.resultType){caseXPathResult.NUMBER_TYPE:return"number";caseXPathResult.BOOLEAN_TYPE:return"boolean";caseXPathResult.STRING_TYPE:return"string";caseXPathResult.FIRST_ORDERED_NODE_TYPE:return"node-set";}}}ok(false,"Unexpected value");thrownewError("Unexpected value");}functiontestParameter(value){lettestProcessor=newXSLTProcessor();testProcessor.setParameter(null,"test",value);letparameter=testProcessor.getParameter(null,"test");checkParameter(value,parameter);testProcessor.importStylesheet(styleDoc);letfragment=testProcessor.transformToFragment(sourceDoc,document);is(fragment.getElementById("result").textContent,getXSLTType(value),"Global parameter has right type in XSLT.");}testParameter(123);testParameter(true);testParameter("abcd");testParameter([document]);testParameter(document.documentElement.childNodes);testParameter(document);testParameter(document.evaluate("id('number')",document,null,XPathResult.NUMBER_TYPE));testParameter(document.evaluate("/",document,null,XPathResult.BOOLEAN_TYPE));testParameter(document.evaluate("id('string')",document,null,XPathResult.STRING_TYPE));testParameter(document.evaluate("/",document,null,XPathResult.FIRST_ORDERED_NODE_TYPE));</script></pre></body></html>