[Webkit-unassigned] [Bug 14101] XSLTProcessor does not accept Nodes as parameter values
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Fri Jan 25 11:39:09 PST 2019
https://bugs.webkit.org/show_bug.cgi?id=14101
--- Comment #18 from William J. Edney <bedney at technicalpursuit.com> ---
Mike -
The codebase I was working from 5 years ago has changed, but I found a chunk of code in a temp file that looked to be more-or-less working code (but probably should just be treated as pseudo-code - I'm sure you'll have to debug a bit):
Assume you have an Array of Objects that contain the parameters you want to feed to the sheet:
params = [
{name: 'foo', value: <Node>},
{name: 'bar', value: <Node>),
...
];
Assume that 'xsltDoc' is the *XSLT* document that you're using to process the source document and 'inputDoc' is the source XML that you're transforming.
for (i = 0; i < params.length; i++) {
// Search the style doc to see if there's an 'xsl:param' element with a name matching params[i].name
paramElem = xsltDoc.evaluate('//param[@name="' + params[i].name '"]', null, XPathResult.ANY_TYPE, null);
if (paramElem) {
// Create an 'xsl:variable' element and set it's name to be the same as the 'xsl:param'
newElem = xsltDoc.createElementNS('http://www.w3.org/1999/XSL/Transform', 'variable');
newElem.setAttribute('name', params[i].name);
// Swap in the 'xsl:variable' element for the 'xsl:param' element
paramElem.parentNode.replaceChild(newElem, paramElem);
// Append the parameter node under the 'xsl:variable' element
newElem.appendChild(params[i].value);
}
}
That's about it. Go ahead and import the sheet:
processor = new XSLTProcessor();
processor.importStylesheet(xsltDoc);
And then run it through the processor:
resultDoc = processor.transformToDocument(inputDoc);
Note that this approach has the distinct disadvantage of modifying your *XSLT* document. If you need to do multiple transformations, you'll want to clone the XSLT document and keep a pristine copying before modifying it like this.
I would caution again that the code above is close, but probably has bugs. Sorry I don't have the original running source to give you.
If you run into issues, feel free to email me directly. My email address is: bedney at technicalpursuit.com
Hope this helps!
Cheers,
- Bill
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20190125/1d3b1e27/attachment.html>
More information about the webkit-unassigned
mailing list