{"record":{"id":"a1045eb329774719","repo":"PHPOffice/PHPWord","slug":"could-not-set-values-for-the-given-xsl-style-sheet","errorCode":null,"errorMessage":"Could not set values for the given XSL style sheet parameters.","messagePattern":"Could not set values for the given XSL style sheet parameters\\.","errorType":"exception","errorClass":"PhpOffice\\PhpWord\\Exception\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpWord/TemplateProcessor.php","lineNumber":246,"sourceCode":"    }\n\n    /**\n     * Applies XSL style sheet to template's parts.\n     *\n     * Note: since the method doesn't make any guess on logic of the provided XSL style sheet,\n     * make sure that output is correctly escaped. Otherwise you may get broken document.\n     *\n     * @param DOMDocument $xslDomDocument\n     * @param array $xslOptions\n     * @param string $xslOptionsUri\n     */\n    public function applyXslStyleSheet($xslDomDocument, $xslOptions = [], $xslOptionsUri = ''): void\n    {\n        $xsltProcessor = new XSLTProcessor();\n\n        $xsltProcessor->importStylesheet($xslDomDocument);\n        if (false === $xsltProcessor->setParameter($xslOptionsUri, $xslOptions)) {\n            throw new Exception('Could not set values for the given XSL style sheet parameters.');\n        }\n\n        $this->tempDocumentHeaders = $this->transformXml($this->tempDocumentHeaders, $xsltProcessor);\n        $this->tempDocumentMainPart = $this->transformXml($this->tempDocumentMainPart, $xsltProcessor);\n        $this->tempDocumentFooters = $this->transformXml($this->tempDocumentFooters, $xsltProcessor);\n    }\n\n    /**\n     * @param string $macro\n     *\n     * @return string\n     */\n    protected static function ensureMacroCompleted($macro)\n    {\n        if (substr($macro, 0, 2) !== self::$macroOpeningChars && substr($macro, -1) !== self::$macroClosingChars) {\n            $macro = self::$macroOpeningChars . $macro . self::$macroClosingChars;\n        }\n","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/TemplateProcessor.php#L228-L264","documentation":"TemplateProcessor::applyXslStyleSheet creates an XSLTProcessor, imports the given XSL stylesheet, and calls setParameter to register $xslOptions; if setParameter returns false it throws 'Could not set values for the given XSL style sheet parameters.' before any transformation runs.","triggerScenarios":"Passing $xslOptions that is not a valid key/value array (e.g. indexed array, nested arrays, non-string values), causing XSLTProcessor::setParameter to reject it.","commonSituations":"Passing an associative array with mixed-type values, numerically indexed arrays, or options read from JSON/config in unexpected shape; forgetting that keys become XSL parameter names which must be valid names.","solutions":["Pass a flat associative array of string keys to string values: ['paramName' => 'value']","Ensure parameter names are valid XSL names (no spaces/special characters)","Cast values to string before passing","Check the stylesheet expects those params (xsl:param) with matching names"],"exampleFix":"// before\n$processor->applyXslStyleSheet($xsl, [['a','b']]); // indexed array\n// after\n$processor->applyXslStyleSheet($xsl, ['a' => 'b']);","handlingStrategy":"validation","validationCode":"function validXslOptions(array $opts): bool {\n    foreach ($opts as $k => $v) {\n        if (!is_string($k) || !preg_match('/^[A-Za-z_][A-Za-z0-9_.-]*$/', $k) || !is_scalar($v)) return false;\n    }\n    return true;\n}\n// use: if (!validXslOptions($xslOptions)) { $xslOptions = []; }","typeGuard":"function isStringMap($v): bool {\n    return is_array($v) && array_is_list($v) === false\n        && count(array_filter($v, 'is_scalar')) === count($v);\n}","tryCatchPattern":"try {\n    $processor->applyXslStyleSheet($xslDom, $opts);\n} catch (\\PhpOffice\\PhpWord\\Exception\\Exception $e) {\n    if (str_contains($e->getMessage(), 'XSL style sheet parameters')) {\n        $processor->applyXslStyleSheet($xslDom, []); // retry without params\n    }\n}","preventionTips":["Pass a flat string-keyed => scalar-valued array","Cast all option values to string","Ensure parameter names match <xsl:param name=\"...\"> in the stylesheet"],"tags":["xslt","parameters","template"],"backgroundTag":"invalid-argument-value","analyzedSha":"aef95c04151b5633cc505f672ddd6a71da900ee1","analyzedAt":"2026-09-14T10:53:58.933Z","contentChangedAt":"2026-09-14T10:53:58.933Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}