[Webkit-unassigned] [Bug 55357] New: XSLT extension functions
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Mon Feb 28 01:43:45 PST 2011
https://bugs.webkit.org/show_bug.cgi?id=55357
Summary: XSLT extension functions
Product: WebKit
Version: 528+ (Nightly build)
Platform: PC
OS/Version: Linux
Status: UNCONFIRMED
Severity: Enhancement
Priority: P2
Component: XML
AssignedTo: webkit-unassigned at lists.webkit.org
ReportedBy: andreas.wictor at xcerion.com
Created an attachment (id=84031)
--> (https://bugs.webkit.org/attachment.cgi?id=84031&action=review)
The patch
In MSIE, Microsoft offers the ability to extend XPath expressions in XSLT stylesheets using
JavaScript functions. This is done by calling the addObject() method on the XSLTemplate ActiveX
object.
This patch adds similar functionality to WebKit by adding methods to the XSLTProcessor object
(modelled after the existing *Parameter() methods): setExtensionObject(), getExtensionObject(),
removeExtensionObject() and clearExtensionObjects().
Basically, a JavaScript object is bound to an XML Namespace and member functions in this object
can then be referenced in the XSLT stylesheet as qualified XPath functions. Exceptions thrown in
the extension functions are propagated back to the XSLTProcessor.transform() caller.
JavaScript code:
var myExt = {
currentDate: function() {
return new Date().toString();
}
};
var proc = new XSLTProcessor();
proc.importStylesheet(stylesheet);
proc.setExtensionObject("urn:x-my-extensions", myExt)
var result = proc.transformToDocument(page);
XSLT stylesheet:
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'
xmlns:my-ext='urn:x-my-extensions'>
...
<address>Generated on <xsl:value-of select='my-ext:currentDate()' /> </address>
...
</xsl:stylesheet>
Please see the attached cross-browser example for the full example.
The patch is pretty straight-forward, except for xml/XSLTExtensions.cpp and
xml/XSLTProcessorLibxslt.cpp. Because the XSLT subsystem uses its own DOM, and we need to pass
nodes between XSLT and JavaScript, we link the two models together using LibXxml's _private
field.
This is why we no longer serialize the DOM to text and feed it into the other DOM's parser, but
instead traverse the tree and manually build the other DOM. This way, we can easily find the
WebKit DOM object when passing arguments to the JavaScript function.
--
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the webkit-unassigned
mailing list