Sablotron Extensions API Reference

Conversions .General

Description

The following function argument conversions are performed:

* An XPath string object is mapped to an ECMAScript string value.
* An XPath number object is mapped to an ECMAScript number value.
* An XPath boolean object is mapped to an ECMAScript boolean value.
* An XPath node-set object is mapped to the ECMAScript binding for the DOM NodeList.
* An XSLT external object is mapped to the ECMAScript object that it wraps.

The following conversions are performed on return values:

* An ECMAScript string value or String object is mapped to an XPath string object.
* An ECMAScript number value or Number object is mapped to an XPath number object.
* An ECMAScript boolean value or Boolean object is mapped to an XPath boolean object.
* An ECMAScript object that is an instance of either Document, Node, NodeList, Attr, Element or CharacterData are mapped to an XPath node-set.
* The ECMAScript null value is mapped to an XSLT external object.
* The ECMAScript undefined value is mapped to an empty node-set.
* Any other ECMAScript object is mapped to an XSLT external object

See Also

Groups [ .General ]
Entries [ Attr | CharacterData | Document | Element | Node | NodeList ]

Example .General

Summary

An example how to use the DOM in JavaScript extension functions. The function returns a sum of all attributes in a nodeset.

Example

Template:
--------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:func="http://www.exslt.org/functions"
   xmlns:my="http://gingerall.org/sablot/myfunc"
   extension-element-prefixes="func"
   exclude-result-prefixes="my">
       
   <xsl:output method="xml" indent="yes"/>
       
   <func:script implements-prefix="my" language="javascript"><![CDATA[
       
   function attrSum(nodeset) {
     var sum = 0;
     for (i = 0; i < nodeset.length; i++) {
       for (j = 0; j < nodeset[i].attributes.length; j++) {
         sum += Number(nodeset[i].attributes.item(j));
       }
     }  
     return sum;
   }
       
   ]]>
   <xsl:fallback>
     <xsl:text>JS extension no supported!</xsl:text>
   </xsl:fallback>
   </func:script>


   <xsl:template match="/root">
     <root>
       <xsl:choose>
         <xsl:when test="function-available('my:attrSum')">
           <xsl:text>The sum of attributes: </xsl:text>
           <xsl:value-of select="my:attrSum(node)"/>
         </xsl:when>
         <xsl:otherwise>Function not available!</xsl:otherwise>
       </xsl:choose>
     </root>
   </xsl:template>
         
       
</xsl:stylesheet>

Data:
--------------------
<?xml version="1.0"?>
<root>
       
   <node a="1" b="2"/>
   <node c="10"/>
   <node a="5" b="6" c="7"/>

</root>

Result:
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<root>The sum of attributes: 31</root>

See Also

Groups [ .General ]

Introduction .General

Summary

This reference guide describes the DOM API for Sablotron Extension functions in JavaScript. Sablotron supports an extension element funct:script element (where funct prefix is bound to the 'http://www.exslt.org/functions' namespace URI) with language="ecmascript" or language="javascript".

Description

The API implementation follows the ECMAScript/DOM2 Language Binding defined in DOM Level2, Appendix E.

However, there are few exceptions from the specifications:

* The DOM model is read only
* DOM functions handling namespaces (with NS in their name) are not supported (throw NOT_SUPPORTED exception).
* XSLTContext.stringValue method is not supported.
* Document.getElementsByTagName{NS} methods aren't supported.
* Element.getElementsByTagName{NS} methods aren't supported.
* DTD definition nodes are not supported.

As the model is read-only and because of distinctions in the DOM and the XPath models, some objects can't be ever instantiated. Those objects (DocumentFragment, Text, Comment, CDATASection, DocumentType, Notation, Entity, EntityReference, ProcessingInstruction) are not supported.

See .Objects for the list of implemented objects.

Type .Conversions and XSLTContext object binding are implemented according to XSLT 1.1, Appendix C3.

See Also

Groups [ .General ]
Documents [ DOM Level2 | XSLT 1.1 ]
Entries [ .Conversions | .Objects | XSLTContext ]

Objects .General

Description

A global object XSLTContext provides an access to XSLT and XPath expession context.

The following DOM objects are available:
DOMException
DOMImplementation
Document
Node
NodeList
NamedNodeMap
CharacterData
Attr
Element

See Also

Groups [ .General ]
Entries [ Attr | CharacterData | DOMException | DOMImplementation | Document | Element | NamedNodeMap | Node | NodeList | XSLTContext ]

Attr Objects

Description

Attr has the all the properties and methods of the Node object as well as the properties and methods defined below.

The Attr object has the following properties:
Attr.name
Attr.specified
Attr.value
Attr.ownerElement

See Also

Groups [ Objects ]
Entries [ Attr.name | Attr.ownerElement | Attr.specified | Attr.value | Node ]

Attr.name Attr

Syntax

       name
NameTypeDescription
(PROP)StringThis read-only property is of type String.

See Also

Groups [ Attr ]

Attr.ownerElement Attr

Syntax

       ownerElement
NameTypeDescription
(PROP)ElementThis read-only property is a Element object.

See Also

Groups [ Attr ]
Entries [ Element ]

Attr.specified Attr

Syntax

       specified
NameTypeDescription
(PROP)BooleanThis read-only property is of type Boolean.

See Also

Groups [ Attr ]

Attr.value Attr

Syntax

       value
NameTypeDescription
(PROP)StringThis property is of type String.

Notes

This property can raise a DOMException object on setting.

See Also

Groups [ Attr ]
Entries [ DOMException ]

CharacterData Objects

Description

CharacterData has the all the properties and methods of the Node object as well as the properties and methods defined below.

The CharacterData object has the following properties:
CharacterData.data
CharacterData.length

The CharacterData object has the following methods:
CharacterData.substringData()

See Also

Groups [ Objects ]
Entries [ CharacterData.data | CharacterData.length | CharacterData.substringData() | Node ]

CharacterData.data CharacterData

Syntax

       data
NameTypeDescription
(PROP)StringThis property is of type String.

Notes

This property can raise a DOMException object on setting and can raise a DOMException object on retrieval.length

See Also

Groups [ CharacterData ]
Entries [ DOMException ]

CharacterData.length CharacterData

Syntax

       length
NameTypeDescription
(PROP)NumberThis read-only property is of type Number.

See Also

Groups [ CharacterData ]

CharacterData.substringData() CharacterData

Syntax

       substringData(offset, count)
NameTypeDescription
offsetNumberThe offset parameter is of type Number.
countNumberThe count parameter is of type Number.
(RET)NodeThis method returns a String.

Notes

This method can raise a DOMException object. The very first item has index 0.

See Also

Groups [ CharacterData ]
Entries [ DOMException | Node ]

DOMException Objects

Description

The DOMException object has the following properties:
DOMException.code

The DOMException class has the following constants:

DOMException.INDEX_SIZE_ERR, type Number, value 1.
DOMException.DOMSTRING_SIZE_ERR, type Number, value 2.
DOMException.HIERARCHY_REQUEST_ERR, type Number, value 3.
DOMException.WRONG_DOCUMENT_ERR, type Number, value 4.
DOMException.INVALID_CHARACTER_ERR, type Number, value 5.
DOMException.NO_DATA_ALLOWED_ERR, type Number, value 6.
DOMException.NO_MODIFICATION_ALLOWED_ERR, type Number, value 7.
DOMException.NOT_FOUND_ERR, type Number, value 8.
DOMException.NOT_SUPPORTED_ERR, type Number, value 9.
DOMException.INUSE_ATTRIBUTE_ERR, type Number, value 10.
DOMException.INVALID_STATE_ERR, type Number, value 11.
DOMException.SYNTAX_ERR, type Number, value 12.
DOMException.INVALID_MODIFICATION_ERR, type Number, value 13.
DOMException.NAMESPACE_ERR, type Number, value 14.
DOMException.INVALID_ACCESS_ERR, type Number, value 15.

See Also

Groups [ Objects ]
Entries [ DOMException.code ]

DOMException.code DOMException

Syntax

       code
NameTypeDescription
(PROP)NumberThis property is of type Number.

Notes

This function always returns FALSE currently.

See Also

Groups [ DOMException ]

DOMImplementation Objects

Description

The DOMImplementation object has the following methods:
DOMImplementation.hasFeature()

See Also

Groups [ Objects ]
Entries [ DOMImplementation.hasFeature() ]

DOMImplementation.hasFeature() DOMImplementation

Syntax

       hasFeature(feature, version)
NameTypeDescription
featureStringThe feature parameter is of type String.
versionStringThe version parameter is of type String.
(RET)BooleanThis method returns a Boolean.

Description

This function always returns FALSE currently.

See Also

Groups [ DOMImplementation ]

Document Objects

Description

Document has the all the properties and methods of the Node object as well as the properties and methods defined below.

The Document object has the following properties:
Document.implementation
Document.documentElement

See Also

Groups [ Objects ]
Entries [ Document.documentElement | Document.implementation | Node ]

Document.documentElement Document

Syntax

       documentElement
NameTypeDescription
(PROP)ElementThis read-only property is an Element object.

See Also

Groups [ Document ]
Entries [ Element ]

Document.implementation Document

Syntax

       implementation
NameTypeDescription
(PROP)DOMImplementationThis read-only property is a DocumentType object.

See Also

Groups [ Document ]
Entries [ DOMImplementation ]

Element Objects

Description

Element has the all the properties and methods of the Node object as well as the properties and methods defined below.

The Element object has the following properties:
Element.tagName

The Element object has the following methods:
Element.getAttribute()
Element.getAttributeNode()
Element.hasAttribute()

See Also

Groups [ Objects ]
Entries [ Element.getAttribute() | Element.getAttributeNode() | Element.hasAttribute() | Element.tagName | Node ]

Element.getAttribute() Element

Syntax

       getAttribute(name)
NameTypeDescription
nameStringThe name parameter is of type String.
(RET)StringThis method returns a String.

See Also

Groups [ Element ]

Element.getAttributeNode() Element

Syntax

       getAttributeNode(name)
NameTypeDescription
nameStringThe name parameter is of type String.
(RET)AttrThis method returns a Attr object.

See Also

Groups [ Element ]
Entries [ Attr ]

Element.hasAttribute() Element

Syntax

       hasAttribute(name)
NameTypeDescription
nameStringThe name parameter is of type String.
(RET)BooleanThis method returns a Boolean.

See Also

Groups [ Element ]

Element.tagName Element

Syntax

       tagName
NameTypeDescription
(PROP)StringThis read-only property is of type String.

See Also

Groups [ Element ]

NamedNodeMap Objects

Description

The NamedNodeMap object has the following properties:
NamedNodeMap.length

The NamedNodeMap object has the following methods:
NamedNodeMap.getNamedItem()
NamedNodeMap.item()

See Also

Groups [ Objects ]
Entries [ NamedNodeMap.getNamedItem() | NamedNodeMap.item() | NamedNodeMap.length ]

NamedNodeMap.getNamedItem() NamedNodeMap

Syntax

       getNamedItem(name)
NameTypeDescription
nameStringThe name parameter is of type String.
(RET)NodeThis method returns a Node object.

See Also

Groups [ NamedNodeMap ]
Entries [ Node ]

NamedNodeMap.item() NamedNodeMap

Syntax

       item(index)
NameTypeDescription
indexNumberThe index parameter is of type Number.
(RET)NodeThis method returns a Node object.

Notes

The very first item has index 0.

See Also

Groups [ NamedNodeMap ]
Entries [ Node ]

NamedNodeMap.length NamedNodeMap

Syntax

       length
NameTypeDescription
(PROP)NumberThis read-only property is of type Number.

See Also

Groups [ NamedNodeMap ]

Node Objects

Description

The Node object has the following properties:
Node.nodeName
Node.nodeValue
Node.nodeType
Node.parentNode
Node.childNodes
Node.firstChild
Node.lastChild
Node.previousSibling
Node.nextSibling
Node.attributes
Node.ownerDocument
Node.namespaceURI
Node.prefix
Node.localName

The Node object has the following methods:
Node.hasChildNodes()
Node.isSupported()
Node.hasAttributes()

The Node class has the following constants:

Node.ELEMENT_NODE, type Number, value 1.
Node.ATTRIBUTE_NODE, type Number, value 2.
Node.TEXT_NODE, type Number, value 3.
Node.CDATA_SECTION_NODE, type Number, value 4.
Node.ENTITY_REFERENCE_NODE, type Number, value 5.
Node.ENTITY_NODE, type Number, value 6.
Node.PROCESSING_INSTRUCTION_NODE, type Number, value 7.
Node.COMMENT_NODE, type Number, value 8.
Node.DOCUMENT_NODE, type Number, value 9.
Node.DOCUMENT_TYPE_NODE, type Number, value 10.
Node.DOCUMENT_FRAGMENT_NODE, type Number, value 11.
Node.NOTATION_NODE, type Number, value 12.

See Also

Groups [ Objects ]
Entries [ Node.attributes | Node.childNodes | Node.firstChild | Node.hasAttributes() | Node.hasChildNodes() | Node.isSupported() | Node.lastChild | Node.localName | Node.namespaceURI | Node.nextSibling | Node.nodeName | Node.nodeType | Node.nodeValue | Node.ownerDocument | Node.parentNode | Node.prefix | Node.previousSibling ]

Node.attributes Node

Syntax

       attributes
NameTypeDescription
(PROP)NamedNodeMapThis read-only property is a NamedNodeMap object.

See Also

Groups [ Node ]
Entries [ NamedNodeMap ]

Node.childNodes Node

Syntax

       childNodes
NameTypeDescription
(PROP)NodeListThis read-only property is a NodeList object.

See Also

Groups [ Node ]
Entries [ NodeList ]

Node.firstChild Node

Syntax

       firstChild
NameTypeDescription
(PROP)NodeThis read-only property is a Node object.

See Also

Groups [ Node ]
Entries [ Node ]

Node.hasAttributes() Node

Syntax

       hasAttributes()
NameTypeDescription
(RET)BooleanThis method returns a Boolean.

See Also

Groups [ Node ]

Node.hasChildNodes() Node

Syntax

       hasChildNodes()
NameTypeDescription
(RET)BooleanThis method returns a Boolean.

See Also

Groups [ Node ]

Node.isSupported() Node

Syntax

       isSupported(feature, version)
NameTypeDescription
featureStringThe feature parameter is of type String.
versionStringThe version parameter is of type String.
(RET)BooleanThis method returns a Boolean.

Notes

This function always returns FALSE currently.

See Also

Groups [ Node ]

Node.lastChild Node

Syntax

       lastChild
NameTypeDescription
(PROP)NodeThis read-only property is a Node object.

See Also

Groups [ Node ]
Entries [ Node ]

Node.localName Node

Syntax

       localName
NameTypeDescription
(PROP)StringThis read-only property is of type String.

See Also

Groups [ Node ]

Node.namespaceURI Node

Syntax

       namespaceURI
NameTypeDescription
(PROP)StringThis read-only property is of type String.

See Also

Groups [ Node ]

Node.nextSibling Node

Syntax

       nextSibling
NameTypeDescription
(PROP)NodeThis read-only property is a Node object.

See Also

Groups [ Node ]
Entries [ Node ]

Node.nodeName Node

Syntax

       nodeName
NameTypeDescription
(PROP)StringThis read-only property is of type String.

See Also

Groups [ Node ]

Node.nodeType Node

Syntax

       nodeType
NameTypeDescription
(PROP)NumberThis read-only property is of type Number.

Description

See Node class constants.

See Also

Groups [ Node ]
Entries [ Node ]

Node.nodeValue Node

Syntax

       nodeValue
NameTypeDescription
(PROP)StringThis property is of type String.

Notes

This property can raise a DOMException object on setting and can raise a DOMException object on retrieval.

See Also

Groups [ Node ]
Entries [ DOMException ]

Node.ownerDocument Node

Syntax

       ownerDocument
NameTypeDescription
(PROP)DocumentThis read-only property is a Document object.

See Also

Groups [ Node ]
Entries [ Document ]

Node.parentNode Node

Syntax

       parentNode
NameTypeDescription
(PROP)NodeThis read-only property is a Node object.

See Also

Groups [ Node ]
Entries [ Node ]

Node.prefix Node

Syntax

       prefix
NameTypeDescription
(PROP)StringThis property is of type String.

Notes

This property can raise a DOMException object on setting.

See Also

Groups [ Node ]
Entries [ DOMException ]

Node.previousSibling Node

Syntax

       previousSibling
NameTypeDescription
(PROP)NodeThis read-only property is a Node object.

See Also

Groups [ Node ]
Entries [ Node ]

NodeList Objects

Description

The NodeList object has the following properties:
NodeList.length

The NodeList object has the following methods:
NodeList.item()

See Also

Groups [ Objects ]
Entries [ NodeList.item() | NodeList.length ]

NodeList.item() NodeList

Syntax

       item(index)
NameTypeDescription
indexNumberThe index parameter is of type Number.
(RET)NodeThis method returns a Node object.

Notes

This object can also be dereferenced using square bracket notation (e.g. obj[1]). Dereferencing with an integer index is equivalent to invoking the item method with that index. The very first item has index 0.

See Also

Groups [ NodeList ]
Entries [ Node ]

NodeList.length NodeList

Syntax

       length
NameTypeDescription
(PROP)NumberThis read-only property is of type Number.

See Also

Groups [ NodeList ]

XSLTContext Objects

Description

The XSLTContext global object has the following properties:
XSLTContext.contextNode
XSLTContext.contextPosition
XSLTContext.contextSize
XSLTContext.currentNode
XSLTContext.ownerDocument

See Also

Groups [ Objects ]
Entries [ XSLTContext.contextNode | XSLTContext.contextPosition | XSLTContext.contextSize | XSLTContext.currentNode | XSLTContext.ownerDocument ]

XSLTContext.contextNode XSLTContext

Syntax

       contextNode
NameTypeDescription
(PROP)NodeContext node from XPath expression context.

See Also

Groups [ XSLTContext ]
Entries [ Node ]

XSLTContext.contextPosition XSLTContext

Syntax

       contextPosition
NameTypeDescription
(PROP)NumberContext position from XPath expression context.

See Also

Groups [ XSLTContext ]

XSLTContext.contextSize XSLTContext

Syntax

       contextSize
NameTypeDescription
(PROP)NumberContext size from XPath expression context.

See Also

Groups [ XSLTContext ]

XSLTContext.currentNode XSLTContext

Syntax

       currentNode
NameTypeDescription
(PROP)NodeCurrent node from XSLT context.

See Also

Groups [ XSLTContext ]
Entries [ Node ]

XSLTContext.ownerDocument XSLTContext

Syntax

       ownerDocument
NameTypeDescription
(PROP)DocumentDocument to be used for creating nodes.

See Also

Groups [ XSLTContext ]
Entries [ Document ]

© 2001 Ginger Alliance
revision 01-12-14
This page was generated by APIDOC