ACTION-66: Mozilla XSLT DOM Interface

Hi,

Below is the interface that we use for XSLT transformations in mozilla. 
There are some things to note about it:

1.
There is no way to specify a stylesheet as a uri. Instead it has to be 
loaded into a DOM by the user. It is useful to load a DOM since then the 
user can modify the stylesheet, but it would be good to have a uri 
signature too.

2.
The interface requires synchronous loading for two reasons.
a) If the stylesheet has <import> or <include> elements those
    stylesheets have to be loaded before importStylesheet returns
b) If the stylesheet uses the document() function those documents
    have to be loaded synchronously during the execution of the
    stylesheet.

3.
The idea was that importStylesheet can be called multiple times to 
import multiple stylesheets (the xslt spec defines how this works). 
However this has not yet been implemented.

4.
I'm not sure what the use case for getParameter is. It is easy enough to 
implement, but it requires that implementations keep the original value 
around indefinitely and can't just convert to an XPath value right away.

5.
We currently support strings, numbers, bools, Nodes, XPathResults, 
NodeLists and arrays of Nodes as argument to setVariable.

/ Jonas

interface XSLTProcessor
{
     /**
      * Import the stylesheet into this XSLTProcessor for
      * transformations.
      *
      * @param style The root-node of a XSLT stylesheet. This can be
      *              either a document node or an element node. If a
      *              document node then the document can contain either a
      *              XSLT stylesheet or a LRE stylesheet.
      *              If the argument is an element node it must be the
      *              xsl:stylesheet (or xsl:transform) element of an XSLT
      *              stylesheet.
      *
      * @exception XSLTException
      */
     void importStylesheet(in Node style);

     /**
      * Transforms the node source applying the stylesheet given by
      * the importStylesheet() function. The owner document of the output
      * node owns the returned document fragment.
      *
      * @param source The node to be transformed
      * @param output This document is used to generate the output
      * @return DocumentFragment The result of the transformation
      *
      * @exception XSLTException
      */
     DocumentFragment transformToFragment(in Node source,
                                          in Document output);

     /**
      * Transforms the node source applying the stylesheet given by the
      * importStylesheet() function.
      *
      * @param source The node to be transformed
      * @return Document The result of the transformation
      *
      * @exception XSLTException
      */
     Document transformToDocument(in Node source);

     /**
      * Sets a parameter to be used in subsequent transformations with
      * this XSLTProcessor. If the parameter doesn't exist in the
      * stylesheet the parameter will be ignored.
      *
      * @param namespaceURI The namespaceURI of the XSLT parameter
      * @param localName    The local name of the XSLT parameter
      * @param value        The new value of the XSLT parameter
      *
      * @exception ILLEGAL_VALUE The datatype of value is
      *                           not supported
      */
     void setParameter(in DOMString namespaceURI,
                       in DOMString localName,
                       in DOMUserData value);

     /**
      * Gets a parameter if previously set by setParameter. Returns null
      * otherwise.
      *
      * @param namespaceURI The namespaceURI of the XSLT parameter
      * @param localName    The local name of the XSLT parameter
      * @return DOMUserData The value of the XSLT parameter
      */
     DOMUserData getParameter(in DOMString namespaceURI,
                              in DOMString localName);
     /**
      * Removes a parameter, if set. This will make the processor use the
      * default-value for the parameter as specified in the stylesheet.
      *
      * @param namespaceURI The namespaceURI of the XSLT parameter
      * @param localName    The local name of the XSLT parameter
      */
     void removeParameter(in DOMString namespaceURI,
                          in DOMString localName);

     /**
      * Removes all set parameters from this XSLTProcessor. This will
      * make the processor use the default-value for all parameters as
      * specified in the stylesheet.
      */
     void clearParameters();

     /**
      * Remove all parameters and stylesheets from this XSLTProcessor.
      */
     void reset();
};

Received on Friday, 3 March 2006 00:19:20 UTC