{ Frameless }

Frameless.addFunctionsNS()

Frameless.addFunctionNS(null, "annoy", function (arg) { 
    alert(Frameless.asString(arg)); 
})
Frameless.select("annoy(//title)")

Frameless.addFunctions()

Add your own functions to use in XPath, using this addFunctions function.

Frameless.addFunctions({
    "log": function (arg) {
        console.log(Frameless.asString(arg));
        return arg;
    }
})


Frameless.select("log(//title)")

Although we don't imagine you would use it voluntary, but if the need arises you can even use namespaces:

Frameless.addFunctions({
    "http://www.w3.org/2005/xpath-functions/math": {
        "cos": function (arg) {
            return Math.cos(Frameless.asNumber(arg));
        }
    }
})

Frameless.registerNamespacePrefix("http://www.w3.org/2005/xpath-functions/math", "math");

Frameless.select("math:cos($var)")

Frameless.addRequestHandler()

The addRequestHandler function can be used to load files in the way you specify, instead of loading them with the standard XMLHttpRequest. It is, for example used for xsl:include, xsl:import, doc(uri) in XPath and Frameless.submit().

An argument object is put together like this:

{
    canRequest: function (method, uri) {
        return true;
    },
    request: function (method, uri, callback, onerror) {
        // your magic...
    }
}

Your canRequest() function will be called everytime a file is loaded. Your code needs to decide if the request may be processed. Requests in the current page (by doc('#xml')) should probably be processed by Frameless, so you need to return false.

Frameless.addRequestHandler({
    canRequest: function (method, uri) {
        return method == "get" && uri == "http://example.com/";
    },
    request: function (method, uri, callback, onerror) {
        setTimeout(function () {
            callback("Hello world");
        }, 0);
    }
})

Frameless.asBoolean()

Frameless.asBoolean() is the JavaScript incarnation of the XPath function boolean().

Examples that will return false:

Examples that will return true:

Frameless.asNumber()

For example:

Frameless.asNumber(Frameless.select("input/@value"))

Frameless.asString()

the asString() function converts all input to a string, following the XPath guidelines specified at http://www.w3.org/TR/xpath-functions/#func-string. You can, for example, convert the textnode of a certain element or the content of an attribute-node to a string value.

This will return the text content of all elements nested in the body element, except for the content of attribute-nodes:

Frameless.asString(document.body)

This will return "-INF":

Frameless.asString(-Infinity)

This will return "Hello":

Frameless.asString([
    document.createTextNode("Hello"),
    document.createTextNode("world")
])

Frameless.autodiscover()

Call this method to make Frameless look for new inline HTML templates. Frameless will remove all data-attributes it successfully processed, so that there's no problem calling this function for a second time.

Frameless.bindInput()

var data = {
    "user": "",
    "pass": ""
};
Frameless.variable("login", data);
Frameless.bindInput(document.getElementById("user"), "$login/user");
Frameless.bindInput(document.getElementById("pass"), "$login/pass");

Frameless.conditional()

When the condition specified in XPath query of the second argument is not met, the node is automatically removed from the document, until the moment conditions change again, then the node will be reinserted into the document.

The first argument is currently expected to be an Element node, the second argument must be an XPath expression.

Permanently remove the body element:

Frameless.conditional(document.body, "false()");

Hide the document after five seconds:

Frameless.conditional(document.body, "current-dateTime() - initial-dateTime() < xs:duration('P5S')");

Frameless.parseXML()

Parses the XML string, and returns a Document node or throws an error in case of a syntax error.

For example:

var doc = Frameless.parseXML("<h1 xmlns='http:///www.w3.org/1999/xhtml'>Hello world</h1>");

Frameless.registerNamespacePrefix()

Use registerNamespacePrefix for registering the namespaces used in your document.

Buildin prefixes:

  • xs: for XML schema
Frameless.registerNamespacePrefix("http://www.w3.org/2000/svg", "svg")
Frameless.select("//svg:circle)")

Frameless.select()

The first argument has to be a string containing an XPath query. The function has an optional second argument: Frameless.select(xpath, context). This argument is the node from which the query will be excecuted. For example which document, which element or which attribute. If not specified Frameless will use the HTML document.

To select the title element:

Frameless.select("//title")

Select all attributes of an element:

Frameless.select("@*", el)
set Frameless.set(xpath, value)

This function sets the string value of the first XPath result. Currently supports element, attribute and text nodes. When the query returns multiple results, only the first item is altered.

Set the <title> element to "Hello World!":

Frameless.set("//title", "Hello World!");

See also: Syncing custom inputs with Frameless

Frameless.setAttribute()

For example:

Frameless.variable("muted", true);
Frameless.setAttribute("//audio | //video", "muted", "{$muted}");

Frameless.setExpressionValue()

An example of the function:

Frameless.setExpressionValue("//h1", "Hello world")

It's JQuery equivalent:

$("h1").text("Hello world");

Frameless.setNowFunction()

An example of the default implementation:

Frameless.setNowFunction(function () {
    return new Date().getTime();
})

Frameless.setNumberFormat()

decl = {
    decimalSeparator: ".", 
    groupingSeparator: ",", 
    minusSign: "-",   
    percent: "%",   
    perMille: "\u2030" // PER MILLE SIGN (U+2030),   
    nan: "NaN",   
    infinity: "INF",   
    zeroDigit: "0",   
    digit: "#",   
    patternSeparator: ";"
};
Frameless.setNumberFormat("nl", {
    decimalSeparator: ",",
    groupingSeparator: ".",
    infinity: "∞",
    nan: "?"
});

Frameless.submit()

The submit function is used to send specific data to the server.

{
    // XPath reference to the element or JSON you want to submit
    ref: "$login/request",

    // XPath reference to the element where you want to store the server response
    targetref: "$login/response",

    // URL to submit the data to; similar to the action attribute on <form>
    resource: "http://example.com/",

    // URL to submit the data to; similar to the method attribute on <form>
    action: "get"
}

Check wether or not a file exists:

Frameless.submit({ resource: ".htaccess" }).then(function () {
    alert("Warning: your .htaccess files should not be accessible!");
});

Post a search to your server, and show the results in your page:

Frameless.submit(
    {
        method: "POST",
        resource: "search.php",
        targetref: "id('search-results')"
    }
).fail(function (e) {
    alert("Search failed: " + e)
});

Frameless.text()

Frameless.variable("$article", null, "doc('article.xml')");
Frameless.text(h1, "$article//title")

Frameless.toXML()

This function saves a Node as XML code. It takes one Node as argument, for example:

Frameless.toXML(document.body)

Returns

"<body><h1>...</h1></body>"

Another frequent way of using it is:

Frameless.toXML(Frameless.select("$data"))

It also has a second argument that allows you to influence indentation, please remind us to write document on this when you need it.

Frameless.transition()

When the result of specified in XPath query changes, the callback function is supplied with the new value and the previous value.

Log all changes to the due date:

Frameless.transition("$issue/due-date", function (value) {
    console.log("New due date: " + Frameless.asString(value));
});

Sync an input field with Frameless without using HTML bindings:

var input = document.getElementById("user");

Frameless.transition("$login/user", function (current, prev) {
    input.value = Frameless.asString(current);
});

input.onchange = function (evt) {
    Frameless.set("$login/user", input.value);
};

See also: Syncing custom inputs with Frameless

Frameless.variable()

For example:

Frameless.variable("title", null, "//h1")

Will be available later on with:
Frameless.select("$title")
which will return an <h1> element

Example 2:

Frameless.variable("name", "Robbert")

Will be available with:
Frameless.select("$name")
which will return "Robbert"

Example 3:

Frameless.variable("data", null, "doc('datasource.xml')")

Will be available with:
Frameless.select("$data")
Which will return the Document Node

XSLT2Processor.clearParameters()

The clearParameters() function removes all parameters set for the XSLT2.0 processor instance.

XSLT2Processor.getParameter()

The getParameter($namespace, $name) function gets the value of the XSLT transform parameter specified with $name.

var xslt = new XSLT2Processor();
xslt.setParameter("{http://example.com/}message", "Hello world!")

XSLT2Processor.getResultDocument()

The getResultDocument($uri) function returns a result document specified by the $uri argument. It will return null if no result document matches the given URI.

XSLT2Processor.getResultDocuments()

The getResultDocuments() function returns an array of result document URI’s, outputted by the previous XSLT transform. It doesn’t take any arguments.

XSLT2Processor.getSuccess()

The getSucces() function returns the callback function set by the setSuccess() function. It doesn’t take any arguments and results in a function.

XSLT2Processor.importStylesheet()

The importStylesheet($xsl) function specifies which stylesheet should be used for an XSLT transform. It returns a Promise that is resolved when the stylesheet (and any includes) has been loaded. The argument must be your something.xsl file that has already been loaded using XMLHttpRequest -- which you can do using jQuery or whatever library you're using. But since you're almost certainly loading the .xsl-file for Frameless, you might as well let Frameless load it by using importStylesheetURI(uri) instead.

importStylesheet() using jQuery

$.ajax(
    {
        url: "stylesheet.xsl"
    }
).done(
    function (doc)
    {
        var xslt, output

        xslt = new XSLT2Processor
        xslt.importStylesheet(doc)
        output = xslt.transformToFragment(document)
        $(output).appendTo('body')
    }
)

XSLT2Processor.importStylesheetURI()

The importStylesheetURI($uri) function returns a Promise and will load the stylesheet (and any includes), resolving the promise when all is done. The argument must be the location of your something.xsl file. Easy does it!

var xslt = new XSLT2Processor

xslt.importStylesheetURI("something.xsl").then(
    function (xslt) {
        var output = xslt.transformToFragment(document)
        document.body.appendChild(output)
    }
)

XSLT2Processor.parseXML()

The parseXML($arg) function will return a new XML document, created from the string specified by the $arg argument.

XSLT2Processor.removeParameter()

I don't need to explain what proc.removeParameter($name) does, but it perhaps is nice to know the difference is with using setParameter("msg", null).

removeParameter() restores any default value of an xsl:param element, whereas setting the parameter to null simple sets the value to nothing.

This will render "Hello world":

This will render nothing:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:example="http://example.com/">

  <xsl:param name="example:message"/>
  ...

XSLT2Processor.reset()

The reset() function resets the XSLT2.0 Processor object to it’s original state. It doesn’t take any arguments and it clears the instance settings for the initial template, the initial mode, the imported stylesheet and all parameters.

It clears parameters supplied using setParameter(), as well as the initial template name and mode set by setInitialMode() and setInitialMode().

XSLT2Processor.serializeXML()

The serializeXML($xml) function serialises the specified DOM node, provided by the $xml argument.

XSLT2Processor.setErrorHandler()

The setErrorHandler($handler) function allows you to specify how to handle errors occurring during processing. The $handler argument specifies the function to which callbacks should be made after the occurrence of errors.

XSLT2Processor.setInitialMode()

The setInitialMode($name) function in XSLT templates can be tagged using a 'mode', where more then one template can match the same element but do different things in different modes.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

  <xsl:template match="chapter">
    <section>...</section>
  </xsl:template>

  <xsl:template match="chapter" mode="table-of-contents">
    <li>...</li>
  </xsl:template>

</xsl:stylesheet>

In this example you can create a table of contents like this:

xslt = new XSLT2Processor
xslt.setInitialMode("table-of-contents")
xslt.transformToDocument(bookDocument)

Then instead of creating a section for all chapters with all the chapters text in it, you can create one list item with just the chapter title, without creating two .xsl documents.

book.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:ns="http://ridiculo.us/">

  <xsl:template match="chapter">
    <section>...</section>
  </xsl:template>

  <xsl:template match="chapter" mode="ns:table-of-contents">
    <li>...</li>
  </xsl:template>

</xsl:stylesheet>

script.js

xslt = new XSLT2Processor
xslt.setInitialMode("{http://ridiculo.us/}table-of-contents")
xslt.transformToDocument(bookDocument)

XSLT2Processor.setInitialTemplate()

The setInitialTemplate($name) function sets the initial template to be used.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:ns="http://ridiculo.us/">

  <xsl:param name="a" select="1"/>
  <xsl:param name="b" select="99"/>

  <xsl:template name="list">
    <ul>
      <xsl:for-each select="$a to $b">
        <li>
          <xsl:value-of select="."/>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>

</xsl:stylesheet>
var xslt, list
xslt = new XSLT2Processor
xslt.setParameter("a", 7)
xslt.setParameter("b", 42)
xslt.setInitialTemplate("list")
xslt.importStylesheet("list.xsl")
list = xsl.transformToFragment(document)
document.body.appendChild(list)

XSLT2Processor.setParameter()

The setParameter($namespace, $name, $value) function specifies the named parameters to be used in the XSLT transform.

var xslt = new XSLT2Processor();

Not your everyday parameter:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:example="http://example.com/">

  <xsl:param name="example:message"/>
  ...
var xslt = new XSLT2Processor();
xslt.setParameter("{http://example.com/}message", "Hello world!")

XSLT2Processor.setSuccess()

The setSuccess($callback) function will set the function to which a callback is made following the transform of the document.

XSLT2Processor.transformToDocument()

The transformToDocument($source) function specifies that the transformation should result in a document object. It takes an $source argument, that specifies the source document or node that will be transformed.

XSLT2Processor.transformToFragment()

The transformToFragment($source, $ownerDocument) function specifies that the transformation should result in a DocumentFragment.

When the templates are meant to create new elements for the current HTML page, this method is for you:


frag = xslt.transformToFragment(window.document)
document.body.appendChild(frag)

window.document says the template output is meant to be used in the current document.

Element must be created specifically for one document, that's why it's necessary to specify the document up front. Using this methods cousin transformToDocument() generates the output in it's very own document, which also means they're not usable in your HTML page.

var xslt = new XSLT2Processor;
xslt.importStylesheetURI("test.xsl");
var doc = sync_GET("test.xml");
var output = xslt.transform(doc);
document.body.appendChild(output);

Or using the jQuery plugin:

$
    .doc('test.xml')
    .xslt('test.xsl')
    .appendTo('body')

XSLT2Processor.transformToHTMLFragment()

The transformToHTMLFragment($source, $ownerDocument) function specifies that the result of the XSLT transform should be put into one or more HTML DocumentFragment objects.

XSLT2Processor.updateHTMLDocument()

The updateHTMLDocument($source, $target) function initiates an XSLT transform on an existing HTML document. The $source argument sets the source document, or document node. The $target argument sets the HTML Document object to update.

Scope.select()

  <xsl:template match="article">
    <xsl:apply-templates select="trace(., 'stuff')" mode="toc"/>
  </xsl:template>

Then use you can use this line in Firebug or in a built-in developer console:

stuff.select('.')

This will return you the <article> Node.

stuff.select('*')

This will select the child elements of the <article>.

Currently the Scope doesn't have access to the namespace prefixes of the stylesheet it was used in, so as a workaround you can use the namespace prefix wildcard to select elements in a namespace:

stuff.select('svg:rect')

For the time being you can use this:

stuff.select('*:rect')

XTDE1260

XSLT error message

You have used an unkown key for the key() function. Have you made a typo in either the key() function arguments or in the <xsl:key name="">?

For example:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:key name="chapter" match="chapter" use="title"/>

  <xsl:template name="text">
    <xsl:apply-templates select="key('chpater', 'Introduction')"/>

See also: XSLT 2.0 specification.

XTDE1280

XSLT error message

You have used an unkown decimal format name, there is no <xsl:decimal-format> element with the specified name. Have you made a typo in a function such as format-number(), format-integer() or in the <xsl:number> element?

For example:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:decimal-format name="x" zero-digit="0"/>

  <xsl:template name="test">
    <xsl:value select="format-number(42, '0000', 'y')"/>
  </xsl:template>

</xsl:stylesheet>

See also: XSLT 2.0 specification.

XTSE0010

XSLT error message

An xsl:-element was found where it doesn't belong. The cause of this error can be any element really. For example; inside a xsl:choose element only xsl:when and xsl:otherwise may occur, all other elements will cause an XTSE0010 error.

See also: XSLT 2.0 specification.

XTSE0020

XSLT error message

An attribute has an invalid value, either on a xsl:-element or an xsl:-attribute on any other element.

See also: XSLT 2.0 specification.

XTSE0090

XSLT error message

You have used an unkown XSLT attribute, probably due to a typo or by accidentally using the xsl: prefix for an attribute.

For example: <xsl:stylesheet vesrion="2.0">.

For example: <p xsl:space="preserve">.

See also: XSLT 2.0 specification.

<for-each>

The xsl:element element is used to create an element node in the output document.

Attributes

AttributeDescription
name="…"Specifies the name of the element to be created. It's value can be set to an expression that is processed at run-time.
namespace="…"Specifies the namespace URI of the element, it's value can also be set to an expression.
use-attribute-sets="…"The use-attribute-sets attribute specifies attributes to be added tot the element. The attributes are specified by a white space separated list of attribute-sets.

<script>

The script element can also be used for executing XSLT instead of JavaScript -- that's what the type attribute is for:

<script src="xslt2.js" defer></script>
<script src="docbook.xsl" type="text/xsl" data-source="article.xml"></script>

For this to work you need to include xslt2.js once too. It is considered a best practice to include that <script> element for xslt2.js as on of the last elements in your HTML page.

You can also specify what mode to use for the initial template:

<script src="docbook.xsl" type="text/xsl" data-source="article.xml" data-mode="svg-clock">
</script>

Or your template doens't require any particular input, just call a named template:

<script src="article.xsl" type="text/xsl" data-template="svg-clock"></script>

The above example is essentially an <xsl:call-template name="svg-clock"/> for use in HTML.

Note: for compatibility with Saxon-CE you can also use data-source instead of data-input, data-initial-template instead of data-template and data-initial-mode instead of data-mode.

Attributes

AttributeDescription
src="…"Where your stylesheet.xsl file is.
type="…"Must be either application/xslt+xml (the official media type for XSLT stylesheets) or text/xsl which is shorter to type.
data-input="…"
data-mode="…"
data-template="…"
language="…"Don't use the language attribute. Ever!

<analyze-string>

Use this element to format regular expression matches differently from the non-matching parts of a string, or to show just the matches.

For example, if you want to highlight all the vowels in a string:

<xsl:analyze-string select='"Hello world"' regexp="[aeiou]+">
  <xsl:matching-substring>
    <u>
      <xsl:apply-templates/>
    </u>
  </xsl:matching-substring>
  <xsl:non-matching-substring>
    <xsl:apply-templates/>
  </xsl:non-matching-substring>
</xsl:analyze-string>

Will result in: Hello world!

The string is split into a sequence of substrings. If the substring matches the regular expression it is a 'matching substring', if it doesn't match the regular expression it is a 'non-matching substring'.

The matching substrings are processed by a xsl:matching-substring element that appears as a child of the xsl:analyze-string instruction. The non-matching substrings are processed by a xsl:non-matching-substring element. Both are optional, so you can only show either one.

Generated regular expressions

Maybe you want to single out one particular value inside a text, like a search term that occurs in search results.

The XSLT standard allows using attribute value templates in the regexp-attribute, but that means you need to escape curly braces in you regular expression by using two curly braces instead of one, rendering the regexp even more comprehensible than they already are.

Attribute value templates for regexp="" are not implemented yet, but when we do we will only recognize expressions that make up the whole attribute. E.g.: a) regexp="{'[' || $letters || ']+'}" will work fine, but regexp="[a-z]{3}" will not be evaluated (making it regexp="[a-z]3" - which is propably not what you expected).

Attributes

AttributeDescription
select="…"select is an XPath expression whose value is the string to be analyzed
regex="…"regex is the regular expression (which may be given as an attribute value template)
flags="…"flags control the way in which the regular expression matching is performed, for example the value "m" indicates multi-line mode.

N.B

When processing matching substrings, it is possible to call the regex-group() function to find the parts of the matching substring that matched particular parenthesized groups within the regular expression.

<apply-imports>

The xsl:apply-imports element applies a template rule from an imported style sheet. It is used when we want to use a template rule from the imported style sheet rather than an equivalent rule in the main style sheet.

The element may contain zero or more xsl:with-param elements (as permitted in XSLT 2.0), to supply parameters to the called template.

Attributes

This element doesn't take any attributes.

N.B

<apply-templates>

The xsl:apply-templates element applies a template to the current element or to the current element's child nodes. Each selected node is processed using the best-match xsl:template defined for that node.

Attributes

AttributeDescription
select="…"If we add a select attribute to the xsl:apply-templates element it will process only the child element that matches the value of the attribute. We can use the select attribute to specify the order in which the child nodes are processed.

N.B

<attribute-set>

The xsl:attribute-set element contains a collection of xsl:attribute elements, a named set of attributes. The attribute-set can be applied as whole to the output document.

Attributes

This element doesn't take any attributes.

N.B

<attribute>

The xsl:attribute element is used to add attributes to elements. The value of the attribute is the content of the xsl:attribute element. The attribute name is interpreted as an attribute value template, so it may contain string expressions within curly braces.

Attributes

AttributeDescription
name="…"The name of the attribute is indicated by the name attribute

N.B

Note: The xsl:attribute element replaces existing attributes with equivalent names.

<call-template>

The xsl:call-template element calls a named template.

Attributes

AttributeDescription
name="…"The name attribute is mandatory and must match the name defined on an xsl:template element.

N.B

To supply parameters to the called template, one or more xsl:with-param elements may be included. The values of these parameters are available to the called template.

<character-map>

The xsl:character-map is currently not enabled in Frameless for performance reasons.

Attributes

AttributeDescription

<choose>

The xsl:choose element is used in combination with xsl:when and xsl:otherwise to express multiple conditional tests. If xsl:when returns false, the next xsl:when element is processed. If all xsl:when elements return false xsl:otherwise is processed. If there is no xsl:otherwise element presented, there will be no output.

Attributes

This element doesn't take any attributes.

N.B

Tip: For simple conditional testing, use the xsl:if element instead.

<comment>

The xsl:comment element is a optional child element of an xsl:template element. The content of the xsl:comment element is text that will be outputted in the form of an XML of HTML comment.

Attributes

This element doesn't take any attributes.

<copy-of>

The xsl:copy-of element copies the value of the select attribute.

Attributes

AttributeDescription
select="…"The select attribute is required, it specifies what to be copied.
copy-namespaces="…"The value is either yes or no. Choose wether the in-scope namespaces of any element nodes copied by this instruction are automatically copied to the result, the default value is yes.

<copy>

The xsl:copy element creates a copy of the current node.

Attributes

AttributeDescription
use-attribute-sets="…"The use-attribute-sets attribute is optional and should only be used if the node is an element. It is a white space separated list of attribute-sets to apply to the output node.

<decimal-format>

The xsl:decimal-format element is a toplevel element, used to define which characters and symbols should be used when converting numbers into strings, it is used in combination with the format-number() function.

Attributes

AttributeDescription
name="…"Specifies a name for the choosen format
decimal-separator="…"Specifies the decimal point character. The default value is "."
grouping-separator="…"Sets the thousands separator character. It's default value is ","
infinity="…"Specifies which string represents infinity. By default the value is "Infinity"
minus-sign="…"Sets the character to represent negative numbers. It's default value is "-"
NaN="…"Specifies the string used when the output is not a number, by default it's value will be "NaN"
percent="…"Specifies the character used to describe percentage. It's default is "%"
per-mille="…"Sets the character used for thezero-digit thousand sign character. By default it is "‰"
zero-digit="…"Sets the digit zero character. It's default value is "0"
digit="…"Specifies the character used to indicate that a digit is required. The default is #
pattern-separator="…"Sets the character used to separate positive and negative subpatterns. By default it is ";"

N.B

Almost all decimal formats are used in combination with the XPath format-number() function.

<document>

The xsl:document element is used to output to a secondary destination.

Attributes

AttributeDescription
href="…"Specifies the destination of the secondary output, it will not be interpreted as an URI but as a filename in a path relative to the current working directory.

N.B

The xsl:document element can only be used when the stylesheet specifies a version attribute higher than 1.0

<element>

The xsl:element element is used to create an element node in the output document.

Attributes

AttributeDescription
name="…"Specifies the name of the element to be created. It's value can be set to an expression that is processed at run-time.
namespace="…"Specifies the namespace URI of the element, it's value can also be set to an expression.
use-attribute-sets="…"The use-attribute-sets attribute specifies attributes to be added tot the element. The attributes are specified by a white space separated list of attribute-sets.

<fallback>

xsl:fallback is used to define the actions to be taken when an instruction-element is used in the stylesheet while no implementation is available.

Attributes

This element doesn't take any attributes.

N.B

<for-each-group>

The xsl:for-each-group element is an instruction that may be used anywhere within a sequence constructor. The instruction allocates the items in an input sequence into groups of items, based on either the common values of a grouping key or on a matching pattern.

Attributes

AttributeDescription
select="…"Specifies the groups for which the instruction is set.
group-by="…"The group-by attribute groups all items having the same grouping key value. This grouping key may have multiple values in which case the item is added to multiple groups.
groups-adjacent="…"This does the same as the group-by attribute, but the difference is that the item has to be an adjacent in the input sequence as well.
group-starting-with="…"This processes the grouping of items in order of a specified pattern. For example when matching a h2 element and it"s following p elements.
group-ending-with="…"This processes the grouping of items in order of a specified pattern. Useful when matching a sequence in which the last item carries a distinguishing attribute.

<for-each>

The xsl:for-each element is an instruction that processes each item in a sequence of items, evaluating the sequence constructor within the element once for each item in that sequence.

Attributes

AttributeDescription
select="…"Specifies the items for which the instruction is set.

N.B

With XSLT1.0 the selected nodes where processed in document order. With XSLT2.0, XPath expressions that would have been valid under XPath 1.0 will return a sequence of nodes that is already in document order, so backwards compatibility is maintained.

<function>

Attributes

AttributeDescription
name="…"The name attribute is required an specifies the name of the function.
as="…"Contains a sequence-type, for example as="xs:string"
override="…"Choose wether the function can be overrided. The value can either be "Yes" or "No".

N.B

Use this element when working with nodes. For heavy computations (numeric etc) use JavaScript functions instead. See addFunction()

<if>

The xsl:if element is used for specifying conditions for processing. If the conditions are met, the content will be processed otherwise they will be ignored.

Attributes

AttributeDescription
test="…"The test attribute is required, the value should be a boolean expression. If the boolean returns true the conditions are met and the content of the if:element will be processed.

<apply-templates>

The xsl:import-schema is used to identify schema components that need to be available before any source document is available. It identifies a namespace containing the names of the components to be imported. The effect is that the names of top-level element and attribute declarations and type definitions from this namespace become available for use within XPath expression.

Attributes

AttributeDescription
namespace="…"The namespace attribute is optional and specifies the URI of the namespace
schema-location="…"The schema-location attribute is optional and specifies the URI of the schema location

<import>

The xsl:import element is used to import another stylesheet into this stylesheet. It has to be the first element in a stylesheet, it must appear before all other elements at the top level.

Attributes

AttributeDescription
href="…"The URI of another stylesheet to be imported

N.B

The elements in the imported stylesheet have a lower priority than the elements in the importing stylesheet.

<include>

The xsl:include element is used to textually include another stylesheet in the current stylesheet. It must appear in the top level of the stylesheet.

Attributes

AttributeDescription
href="…"The href attribute specifies the URI of the stylesheet to be included.

<key>

The xsl:key element is used to declare an attribute, or other value, that may be used as a key to identify nodes using the key() function within an expression. Each xsl:key definition declares a named key, which must match the name of the key used in the key() function.

Attributes

AttributeDescription
name="…"Specifies the name of the key, this name must match the name of the key() function.
match="…"The match attribute defines, with a pattern, the set of nodes to which the key applies.
use="…"The use attribute is an expression, which is evaluated for each matched element. It defines for each of these matched elements the value of the key.
collation="…"The collation attribute can be used when comparing strings.

N.B

The xsl:key element must be defined at the top level of the stylesheet.

<matching-substring>

<message>

The xsl:message element sends a message and causes the creation of a new document. The content of the message may be specified by using either the optional select attribute or the sequence constructor that forms the content of the element. It is also possible to use both.

Attributes

AttributeDescription
select="…"Optionally specifies the content of the created message
terminate="…"The termintate attribute has a value of either "Yes" or "No" (the default is "No"). If the value is set to "Yes", the processing of the stylesheet will be terminated after issuing the message.

<namespace>

The xsl:namespace instruction creates a namespace node.

Attributes

AttributeDescription
name="…"The name attribute defines the namespace prefix of the created namespace node.
select="…"The namespace URI may be set using this attribute, it can also be set in the content of the xsl:namespace element content.

<next-match>

The xsl:next-match element finds the rule that matches the next element using an algorithm pretending the if the current node and the preceding nodes didn't exist while matching the template.

Attributes

This element doesn't take any attributes.

<non-matching-substring>

<number>

The xsl:number element creates a formatted number. The output of the element is a newly constructed text node containing the formatted number as it"s string value.

Attributes

AttributeDescription
count="…"The count attribute contains an XPath expression that specifies what nodes are to be counted.
level="…"The level attribute specifies how the sequence number is to be assigned, the value is either "single", "multiple" or "any".
form="…"The form attribute contains an XPath expression that specifies the position in which the counting will start.
value="…"The value attribute specifies a number that is used in place of a sequence generated number
format="…"The format attribute defines the output format for the number
lang="…"The lang attribute sets the language alphabet to be used for the numbering
letter-value="…"The letter-value attribute defines if the numbering in the selected language is alphabetic or traditional. It's default value is alphabetic
grouping-separator="…"The grouping-separator attribute defines which character should be used to separate groups of digits. The default value is the comma
grouping-size="…"The grouping-size attribute defines how many digits are in the groups that are being separated by the character specified in the grouping-separator attribute. It's default value is 3.

<otherwise>

<output-character>

<output>

The xsl:output element controls the format of the output files, resulting from the transformation. It is optional, but if used, it has to be a top-level element immediately below the xsl:stylesheet element. There may be multiple xsl:output elements.

Attributes

AttributeDescription
method="…"The method attribute defines the output format. Values may be XML, HTML, text and name. The default value is XML.
version="…"The version attribute sets the W3C version number for the output format.
encoding="…"The encoding attribute sets the value of the encoding attribute in the output as a string value.
omit-xml-declaration="…"The omit-xml-declaration attribute can have two values: "yes" specifies that the XML declaration should be omitted in the output. "no", the default value, specifies that the XML declaration should be included in the output.
standalone="…"The standalone attribute can have two values, "yes" or "no". "Yes" specifies that a standalone declaration should occur in the output. "No", the default, specifies that the XML declaration should not occur in the output.
doctype-public="…"The doctype-public attribute sets the value of the public attribute of the doctype declaration in the output.
cdata-section-elements="…"The cdata-section-elements attribute is a list with white-space separated elements whose text contents should be written as CDATA sections
indent="…"The indent attribute has two possible values. "Yes" couses the indentation of the output according to it"s hierarchic structure. "No" couses the output not to be indented.
media-type="…"The media-type attribute defines the MIME type of the output, it's default value is "text/xml".

<param>

The xsl:param element is used to set a parameter to a template or stylesheet. It must be used as an immediate child of the xsl:stylesheet element.

Attributes

AttributeDescription
name="…"The name attribute is required to define the name of the parameter.
select="…"The value of the parameter may be defined either by the optional select attribute, or by the content of the xsl:param element.

N.B

Elements that use xsl:param

<perform-sort>

The xsl:perform-sort element is used to return a sorted sequence.

Attributes

AttributeDescription
select="…"There is an optional attribute select, it defines the initial sequence.

N.B

The child element of xsl:perform-sort is xsl:sort

<preserve-space>

The xsl:preserve-space element is used at the top level of the stylesheet to define elements in the source document for which white-space nodes are significant and should be retained.

Attributes

AttributeDescription
elements="…"The elements attribute defines a space-separated list of element names

N.B

For more information look at the "white space handling" page

<processing-instruction>

The xsl:processing-instruction causes an XML processing instruction to be output.

Attributes

AttributeDescription
name="…"The required name attribute which gives the name of the processing instruction

<result-document>

The xsl:result-document element is used to direct output to a secondary output destination.

Attributes

AttributeDescription
format="…"The format attribute gives the name of an xsl:output element that describes the serialisation format.
href="…"the href attribute gives the URI for the result document
validation="…"The validation attribute specifies the validation type of the document it can either be "strict" "lax" "preserve" "strip"
type="…"
method="…"The method attribute specifies the type of content, it can either be "xml" "html" "xhtml" or "text"
byte-order-mark="…"The byte-order-mark attribute can either be "yes" or "no"
cdata-section-elements="…"
doctype-public="…"
doctype-system="…"
encoding="…"
escape-uri-attributes="…"The escape-uri-attributes attribute can either be "yes" or "no"
include-content-type="…"The include-content-type attribute can either be "yes" or "no"
indent="…"The indent element specifies if the content should be indented, the value can either be "yes" or "no"
media-type="…"
normalization-form="…"The normalization-form attribute can have the following values: "NFC", "NFD", NFKC", "fully-normalized", "none", or be an nmtoken
omit-xml-declaration="…"The omit-xml-declaration attribute can either be "yes" or "no"
standalone="…"The standalone attribute can be either "yes", "no" or "omit"
undeclare-prefixes="…"The undeclare-prefixes attribute can either be "yes" or "no"
use-character-maps="…"
output-version="…"

<sequence>

The xsl:sequence element is used to construct a sequence of nodes and/or atomic values. This sequence will be returned as the result of the instruction.

Attributes

AttributeDescription
select="…"The items for the result sequence are selected using the select attribute

<strip-space>

The xsl:strip-space element is used to define elements in the source document for which the white-space nodes are not significant. It causes the extra whitespace to be removed from the tree before processing.

Attributes

AttributeDescription
elements="…"The elements attribute defines a list of space-separated element names

N.B

For more information about white space, read the "white space handling" page.

<template>

The xsl:template element defines a template containing a sequence constructor for creating nodes and/or atomic values. It can be used as a template rule called by matching nodes agains a pattern, or as a named template called by name. It is also possible to be used in both ways. The element must have either a match attribute (specifies a template rule) or a name attribute (specifies a named template).

Attributes

AttributeDescription
match="…"The match attribute specifies the pattern for the template to match
name="…"The name attribute specifies a name for the template
priority="…"The priority attribute sets a number which indicates the priority of the template
mode="…"Specifies a mode for the template
as="…"The as attribute defines the required type of result

<text>

The xsl:text element is used for directly outputting it"s content, mainly to allow white space to be output.

Attributes

AttributeDescription
disable-output-escaping="…"The disable-output-escaping attribute defines whether special characters should be outputted as is. The default is "no" and causes the output of a character lik "<" to be outputted as "&lt;".

N.B

For more information about white space, take a look at the "white space handling" page.

<transform>

<value-of>

The xsl:value-of element evaluates an expression as a string, the result of the instruction is a new text node which will be outputted to the current output stream. The value of the text node may be set by using the select attribute or the content of the element. You have to choose, these options are mutually exclusive, and one of them must be set.

Attributes

AttributeDescription
select="…"The select attribute can be used to define the value of the new text node
separator="…" The separator attribute will cause the effective value of the attribute to be used to separate adjacent items in the result sequence.

N.B

The xsl:value-of is similair to the mustache template: <h1>{{title}}</h1> is equivalent to <h1> <xsl:value-of select="title"/> </h1>

<when>

<with-param>

The xsl:with-param element is used to define the actual parameter to the template. It may be used within an xsl:call-template, xsl:apply-templates or xsl:apply-imports element.

Attributes

AttributeDescription
name="…"The name attribute is required to define the name of the parameter.
select="…"The value of the parameter may be defined by a select attribute, or by the contents of the xsl:param element.
as="…"The as attribute describes the parameters of the called template
tunnel="…"The tunnel attribute may be used to indicate that a parameter is a tunnel parameter, it"s default is "No".

N.B

Related elements:

data-if

You can trigger removing and inserting parts of your HTML page using the data-if="" attribute. Use this attribute to expand and collapse things.

The data-if takes an XPath query. If that query returns false, the element will be removed.

It can be used to show an element only if a user is logged in for example.

<div data-if="$logged-in">
  <p>Hi, welcome back!</p>
</div>

<div data-if="not($logged-in)">
  <form action="login">
    ... a login form
  </form>
</div>

Running Frameless.variable("$logged-in", false) (from your developer console) would hide the element, then executing Frameless.variable("$logged-in", true) would make it re-appear.

data-ref

The data-ref attribute is used for form elements, to link the input element to an other element selected by the XPath query.

If the value of the input element changes, the value of the selected element is automatically updated. If the value of the linked element changes in some way, the value of the input element changes too

<input data-ref="$user/name"></input>

If the XPath query returns a h1 element, the two are connected and the values will update eachother.

data-text

The data-text attribute takes text and or an XPath query as input. The value of the attribute replaces the contents of the element.

<li data-text="Inbox ({count(mail[@unread='true'])})">?</li>

Will return

<li>Inbox (8)</li>
If the query returns 8 unread e-mails

axis specifiers

Axis specifiers indicate navigation direction within the tree representation of the document.

The axes available are:

Full Syntax Abbreviated Syntax Notes
ancestor
ancestor-or-self
attribute @ @abc is short for attribute::abc
child xyz is short for child::xyz
descendant .//
descendant-or-self
following
following-sibling
namespace
parent .. .. is short for parent::node()
preceding
preceding-sibling
self . . is short for self::node()

As an example of using the attribute axis in abbreviated syntax, //a/@href selects the attribute called href in <a> elements anywhere in the document. The expression . (an abbreviation for self::node()) is most commonly used within a predicate to refer to the currently selected node. For example, h3[.='See also'] selects an element called <h3> in the current context, whose text content is "See also".

Selecting (from) the root node

The root node is selected with a single slash /. In HTML this will not be the <html> element, but the 'document node' that contains the <html> element. Selecting the <html> element can be done using /html.

expressions

Simple expressions

The compact notation allows many defaults and abbreviations for common cases.

Given a source document containing:

<div>
  <p>
    <img src="foo.jpg"/>
  </p> 
</div>
The simplest XPath takes a form such as:
/div/p/img
Which selects <img> elements that are children of <p> elements that are children of a <div> element.

The XPath syntax is designed to mimic URI (Uniform Resource Identifier) and Unix-style file path syntax.

An example of more complex expressions

More complex expressions can be constructed by specifying an axis other than the default 'child' axis, a node test other than a simple name, or predicates, which can be written in square brackets after any step.

For example, the expression:

A//B/*[1]
Selects the first element [1], whatever its name *, that is a child / of a <B> element that itself is a child or other, deeper descendant // of an <A> element that is a child of the current context node (the expression does not begin with a /). If there are several suitable <B> elements in the document, this actually returns a set of all their first children.
(A//B/*)[1]
Returns just the first node.

Documentation

In the sidebar you can find our documentation of the XPath expressions. If you want to read the full XPath specification you can take a look at the specification provided by the W3C.

nodes

Types of nodes

In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes.

Supported documents are treated as trees of nodes. The topmost element of the tree is called the root element.

Look at the following XHTML document:

<!DOCTYPE html>
<html>
  <body>
    <h1 id="logo">Frameless</h1>
    <h2>About Frameless</h2>
    <p>Frameless is a reactive template engine for easy development of applications</p>
  </body>
</html>
Example of nodes and atomic values in the XHTML document above:
Root element node
<html>

Element node
<h1>Frameless</h1>

Attribute node
id="logo"

Atomic values are nodes with no children or parent.
About Frameless
"logo"

operators

General Comparisons
Operator Meaning
= $x = $y equals. True when one of the items in $x is also in $y
!= $x != $y not equals. True when none of the items in $x is also found in $y
< $x < $y less than
<= $x <= $y less than or equal to
> $x > $y greater than. Note that in attributes it must be escaped as &gt;.

E.g.: <xsl if test="$x &gt; 5">
>= $x >= $y greater than or equal to. Note that in attributes it must be escaped as &gt;=.

E.g.: <xsl if test="$x &gt;= 5">
Value Comparisons

XPath 2.0 has introduced a completely new set of operators for comparing single atomic values. These are shown in the table below.

Warning: all these operators have in common that if one of the sides is empty (null) the value is neither true nor false, but null. This is especially counterintuitive in for 'not equals' operator (ne): @class ne = 'hidden' will be falsy when there is no 'class' attribute, even though the attributes value isn't equal to 'hidden': because @class is null the result will be null which in turn will evaluate to false in an if/else-statement. So, if one of the operands is optional it might be more convenient to use != instead.

Operator Meaning
eq equals
ne not equals
lt less than
le less than or equal to
gt greater than
ge greater than or equal to

These were introduced primarily because they have much cleaner and more predictable behavior than the XPath 1.0 operators = , != , < , <= , > , and >= . The XPath 1.0 operators however are still available.

variables

How to declare a variable

You can declare a variable in the Frameless template syntax or in JavaScript.

To declare your variable in the Frameless template syntax:

// If the variable contains a string, use the value attribute
<variable name="foo" value="Hello World!"/>

// If the variable contains a number
<variable name="foo" select="42"/>

// If the variable contains a sequence
<variable name="foo" select="(0, 1, 1, 2, 3)"/>

// If the variable contains an XPath query
<variable name="age" select="//div/p[@class='age']"/>

// You can also declare an empty variable
<variable name="foo"/>

To declare a variable in JavaScript:

Declare a variable with a normal value
Frameless.variable("name", value)

Declare a variable with in the value the outcome of an XPath query
Frameless.variable("name", null, "//person[1]/name")

Usage of variables in XPath

QName($paramURI, $paramQName)

The QName($paramURI, $paramQName) function constructs an xs:QName value, given a namespace URI provided by the $paramURI argument and a lexical QName provided by the $paramQName argument.

Arguments

ArgumentType
$paramURIxs:string
$paramQNamexs:string
Return valuexs:QName

Examples

QName("http://frameless.io/index.html", "documentation")returns an xs:QName with namespace URI = "http://frameless.io/index.html", local name = "documentation" and prefix="".

abs($arg)

The abs(num) function accepts any numeric value and returns its absolute value. The result type depends on the numeric type of the argument.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

abs(4.2)4.2
abs(-4.2)4.2

acos($arg)

The acos(num) return the arccosine of a number.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

acos(1)0

adjust-date-to-timezone($arg, $timezone)

The adjust-date-to-timezone(date, timezone) function adjusts a date to a specific timezone, or no timezone. The $timezone argument has to be set as an xs:dayTimeDuration, for example PT5H for US Eastern Standard Time. If the timezone argument is left empty, the timezone will be set to no timezone. The $arg argument specifies the date to adjust.

Arguments

ArgumentType
$argxs:date
$timezonexs:dayTimeDuration
Return valuexs:date

Examples

adjust-date-to-timezone( xs:date("2013-01-11"), xs:dayTimeDuration("-PT8H"))2013-01-11-08:00
adjust-date-to-timezone( xs:date("2013-01-11-03:00"), xs:dayTimeDuration("-PT8H"))2013-31-10-08:00

adjust-dateTime-to-timezone($arg, $timezone)

The adjust-dateTime-to-timezone(datetime, timezone) function adjusts a dateTime to a specific timezone, or no timezone. The $timezone argument has to be set as an xs:dayTimeDuration, for example PT5H for US Eastern Standard Time. If the timezone argument is left empty, the timezone will be set to no timezone. The $arg argument specifies the dateTime to adjust.

Arguments

ArgumentType
$argxs:dateTime
$timezonexs:dayTimeDuration
Return valuexs:dateTime

Examples

adjust-dateTime-to-timezone( xs:dateTime("2013-01-11T22:00"), xs:dayTimeDuration("-PT8H"))2013-01-11T22:00-08:00
adjust-dateTime-to-timezone( xs:dateTime("2013-01-11T22:00-03:00"), xs:dayTimeDuration("-PT8H"))2013-01–11T19:00-08:00

analyze-string($input, $pattern, $flags)

The analyze-string(input, pattern, flags) function analyzes a string using a regular expression. It returns a structure that identifies which parts of the input string matched or failed to match the regular expression.

Arguments

ArgumentType
$inputxs:string
$patternxs:string
$flagsxs:string
Return valueelement(analyze-string-result)

atan($arg)

The atan(num) return the arctangens of a number.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

atan(0.5)0.46364760900080615

atan2($x, $y)

The atan2(x, y) return the arctangent of the quotient of the numbers.

Arguments

ArgumentType
$xnumeric
$ynumeric
Return valuenumeric

Examples

atan2(0, -0)3.141592653589793
atan2(0, 0)0

available-environment-variables()

This function is of no use in the browser, but it will be available in Node.js

avg($arg)

The avg((arg, arg, …)) function returns the average, the sum of the divided by the number, of the values in the input sequence $arg.

Arguments

ArgumentType
$argxs:anyAtomicType
Return valuexs:anyAtomicType

Examples

avg((1,2,3))2

N.B

Implemented, but only for numbers, not for durations. So for now, the input can only be a number.

base-uri($arg)

The base-uri($arg) returns the value of the base-uri property of the current or specified node. If the $arg is a document node, this function usually returns the URI from which the document was retrieved.

Arguments

ArgumentType
$argnode()
Return valuexs:anyURI

N.B

Does not work for copied nodes, they will be resolved against the document-uri() of the owner document. Information about xml:base attributes of the original node is discarded, because that's how the browser DOM works.

boolean($arg)

The boolean(arg) function returns the effective boolean value for a number, string or node-set.

Arguments

ArgumentType
$argitem()
Return valuexs:boolean

Examples

boolean("")false
boolean(0)false
boolean("0")true
boolean("false")true

ceiling($arg)

The ceiling(num) function returns the smalles integer that is greater than the number argument.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

celing(3.14)4

codepoint-equal($comp1, $comp2)

The codepoint-equal(comp1, comp2) function returns true if the value of comp1 is equal to comp2 according to the Unicode code points.

Arguments

ArgumentType
$comp1xs:string
$comp2xs:string
Return valuexs:boolean

Examples

codepoint-equal("abc", "abc")true
codepoint-equal("abc", "ab c")false

codepoints-to-string($arg)

The codepoints-to-string(int, int, …) function returns a string from a sequence of codepoints.

Arguments

ArgumentType
$argxs:integer
Return valuexs:string

Examples

codepoints-to-string(84, 104, 233, 114, 232, 115, 101)Thérèse

collection()

No use in the context of the browser. Always returns the empty sequence.

compare($comp1, $comp2)

The compare(comp1, comp2) function returns the difference between comp1 and comp2. -1 if comp1 is less than comp2, 0 if comp1 and comp2 are equal and 1 if comp1 is greater than comp2.

Arguments

ArgumentType
$comp1xs:string
$comp2xs:string
Return valuexs:integer

Examples

compare('a', 'b')-1
compare('ghi', 'ghi')0
compare('b', 'a')1
compare('a', 'B')1

N.B

Doesn't yet use the actual collations, so $collation cannot be used as the third argument.

concat($arg)

The concat(string, string, …) combines all the arguments into one string.

XPath 3.0 introduced a new syntax for string concatenation:

'Hello ' || $name || '!'

Yeah, it looks a lot like an or-operator. It isn't though. Go make your stylesheets more handsome and switch to this operator instead of using concat()!

Arguments

ArgumentType
$argxs:anyAtomicType
Return valuexs:string

Examples

concat("Frameless", "is", "great!")"Frameless is great!"

contains($arg1, $arg2)

The contains($arg1, $arg2) function checks if one string contains the other. It returns true if $arg1 contains the characters of $arg2.

Arguments

ArgumentType
$arg1xs:string
$arg2xs:string
Return valuexs:boolean

Examples

contains("frameless", "e")true
contains("frameless", "less")true
contains("frameless", "q")false
contains("frameless", "")true

copy-of()

This is an XPath 3.0 function, documentation follows when implemented.

cos($arg)

The cos(num) return the cosine of a number.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

cos(pi() * 2)1
cos(pi())-1
cos(0)1

count($arg)

The count(($arg, $arg, …)) function returns the count of items in a sequence.

Arguments

ArgumentType
$argitem()
Return valuexs:integer

Examples

count((1, 2, 3))3

current-date()

The current-date() function returns the current date. It doesn"t take arguments and returns the current date including the implementation-dependent time zone.

When you're using the 'current time' in XSLT, it will return the same date throughout the transformation, so when your program runs at exactly on midnight results will be consistent accross the output document.

Arguments

This element doesn't take any arguments.

Examples

current-date()2013-11-01-22:00

current-dateTime()

The current-dateTime() function returns the current date and time. It doesn"t take arguments.

When you're using the 'current time' in XSLT, it will return the exactly the same time throughout the transformation.

Arguments

This element doesn't take any arguments.

Examples

current-dateTime()2013-11-01T22:40:23.83-05:00

current-time()

The current-time() function returns the current time. It doesn"t take arguments and returns the current time including the implementation-dependent time zone.

When you're using the 'current time' in XSLT, it will return the exactly the same time throughout the transformation.

Arguments

This element doesn't take any arguments.

Examples

current-time()22:40:23.83-05:00

N.B

If the current-time function is called again in the same query, it will return the same value as the first time.

data($arg)

The data($arg, $arg, …) function takes a sequence of items and returns a sequence of atomic values.

Arguments

ArgumentType
$arg item()
Return valuexs:anyAtomicType

dateTime($arg1, $arg2)

The dateTime($arg1, $arg2) function converts the date and time arguments to a dateTime.

Arguments

ArgumentType
$arg1xs:date
$arg2xs:time
Return valuexs:dateTime

Examples

dateTime( xs:date("2013-11-01), xs:time("22:30:45-05:00"))2013-11-01T22:30:45-05:00

day-from-date($arg)

The day-from-date($arg) function returns an integer that represents the day in the localised value of the argument.

Arguments

ArgumentType
$argxs:date
Return valuexs:integer

Examples

day-from-date(xsl:date("2013-10-01"))31

day-from-dateTime($arg)

The day-from-dateTime($arg) function returns an integer that represents the day/time in the localised value of the argument.

Arguments

ArgumentType
$argxs:dateTime
Return valuexs:integer

Examples

day-from-dateTime(xsl:dateTime("2013-10-01T22:00:42"))31

days-from-duration($arg)

The days-from-duration($arg) function calculates the total number of whole days in a normalised xs:duration value.

Arguments

ArgumentType
$argxs:duration
Return valuexs:integer

Examples

days-from-duration( xs:dayTimeDuration("-PT24H"))-1
days-from-duration( xs:dayTimeDuration("P7D"))7

deep-equal($param1, $param2, $collation)

The deep-equal($param1, $param2, collation) function checks if two nodes have the same content and attributes. It will return true when $param1 and $param2 have the same content and attributes, otherwise it will return false.

Arguments

ArgumentType
$param1item()
$param2item()
$collationxs:string
Return valuexs:boolean

Examples

deep-equal(1, 1)true
deep-equal((1, 2), (1.0, 2.0))true
deep-equal((1, 2), (2, 1))false

default-collation()

The default-collation() function returns the value of the default collation.

In Frameless this function will always return "http://www.w3.org/2005/xpath-functions/collation/codepoint"

Arguments

This element doesn't take any arguments.

Examples

default-collation()http://www.w3.org/2005/xpath-functions/collation/codepoint

distinct-values($arg, $collation)

The distinct-values(($arg, $arg, …), collation) function returns the distinct values in a sequence.

Arguments

ArgumentType
$argxs:anyAtomicType
$collationxs:string
Return valuexs:anyAtomicType

Examples

distinct-values((2, 3, 4, 3, 4))(2, 3, 4)

doc-available($uri)

The doc-available($uri) function returns true when the doc() function returns a document node. In any other case it will return false.

Arguments

ArgumentType
$urixs:string
Return valuexs:boolean

Examples

doc-available("http://www.frameless.io/index.html')true
doc-available("http://www.frameless.io/foo.html')false

N.B

Warning: does a synchronous HEAD request.

doc($uri)

The doc($uri) function opens a document based on the by the argument provided URI.

Arguments

ArgumentType
$urixs:string
Return valuedocument-node()

Examples

doc("http://www.frameless.io/index.html')the document node of the document at http://www.frameless.io/index.html

N.B

Warning: does a synchronous request.

document-uri($arg)

The document-uri($arg) function will return the URI associated with the document node.

Arguments

ArgumentType
$argnode()
Return valuexs:anyURI

Examples

document-uri(doc("http://www.frameless.io/index.html'))http://www.frameless.io/index.html

element-with-id()

This is an XPath 3.0 function, documentation follows when implemented.

empty($arg)

The empty($arg, $arg, …) function checks if the value is an empty sequence. It returns true if the value of the arguments is an empty sequence.

Arguments

ArgumentType
$argitem()
Return valuexs:boolean

Examples

empty(("a", "b", "c"))false
empty(())true
empty(0)false

encode-for-uri($uri-part)

The encode-for-uri($uri-part) function encodes reserved characters for use in the path of an URI. All characters except letters a-z A-Z, digits 0-9, hyphen, underscore, period and tilde are escaped.

Arguments

ArgumentType
$uri-partxs:string
Return valuexs:string

Examples

encode-for-uri("Frameless % processor.pdf")Frameless%20%25%20processor.pdf

ends-with($arg1, $arg2, $collation)

The ends-with($arg1, $arg2) function checks if $arg1 ends with $arg2, if so it returns true.

Arguments

ArgumentType
$arg1xs:string
$arg2xs:string
$collationxs:string
Return valuexs:boolean

Examples

ends-with("XML", "X")false
ends-with("Frameless", "less")true

environment-variable()

Of no use in the browser, but it will be available in Node.js

error($error, $description, $error-object)

The error($error, $description, $error-object) function raises a custom error. It allows you to stop the execution of the query with a specific error message. The $description and $error-object arguments are optional.

Arguments

ArgumentType
$errorxs:QName
$descriptionxs:string
$error-objectitem()
Return valuenone

Examples

error()An error is thrown
error(QName('dty:ProdNum'), 'Missing number', $item)An error is thrown

escape-html-uri($uri)

The escape-html-uri($uri) function escapes all characters except for printable ASCII characters.

Arguments

ArgumentType
$urixs:string
Return valuexs:string

Examples

escape-html-uri("http://frameless.io/second%20édition.html')http://frameless.io/second%20%C3%A9dition.html
escape-html-uri("http://frameless.io)http://frameless.io

exactly-one($arg)

The exactly-one($arg) function returns a sequence if it contains exactly one item, if this condition is not met it will throw an error (FORG0005).

Why does function even exist?

This function is not equivalent to count($arg) = 1, because it will throw an error instead of returning false. This function could in the future be used to speed up queries because static analysis could make more assumptions about this query.

In short: don't use this function in Frameless. Yet.

Arguments

ArgumentType
$argitem()
Return valueitem()

Examples

exactly-one(())Error FORG0005
exactly-one("a")a
exactly-one(("a", "b"))Error FORG0005

exists($arg)

The exists($arg, $arg, …) function checks if the value of the arguments is not an empty sequence. If this condition is met it will return true, otherwise it will return false.

Arguments

ArgumentType
$argitem()
Return valuexs:boolean

Examples

exists(("a", "b", "c"))true
exists("")true
exists(())false
exists(false()true

exp($x)

The exp(x) returns Eulers constant to the power x, with x being the number argument, so exp(1) returns Eulers constant.

Arguments

ArgumentType
$xnumeric
Return valuenumeric

Examples

exp(1)2.718281828459045

exp10($x)

The exp10(x) returns 10x (10 to the power x), with x being the number argument, so exp(1) returns Eulers constant.

Arguments

ArgumentType
$xnumeric
Return valuenumeric

Examples

exp10(3)1000
exp10(0)1

false()

The false() function just means false in XPath. It is not just false like in JavaScript: that syntax cannot not be used because that already means looking for an element named 'false'. To no surprise it"s counterpart is true().

It doesn"t take any arguments; if you want cast to a boolean you can use boolean() and not().

Arguments

This element doesn't take any arguments.

Examples

false()false

filter()

This is an XPath 3.0 function, documentation follows when implemented.

floor($arg)

The floor($arg) function rounds down to the next lowest integer, and returns the largest integer that is smaller than the numeric argument.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

floor(3.14)3
floor(-4.2)-5

fold-left()

This is an XPath 3.0 function, documentation follows when implemented.

fold-right()

This is an XPath 3.0 function, documentation follows when implemented.

for-each-pair()

This is an XPath 3.0 function, documentation follows when implemented.

for-each()

This is an XPath 3.0 function, documentation follows when implemented.

format-date($value, $picture, $language, $calendar, $place)

The format-date($value, $picture) or format-date($value, $picture, $language, $calendar, $place) function returns a string containing an xs:date value formatted for display.

Arguments

ArgumentType
$valuexs:date
$picturexs:string
$languagexs:string
$calendarxs:string
$placexs:string
Return valuexs:string

format-dateTime($value, $picture, $language, $calendar, $place)

The format-dateTime($value, $picture) or format-dateTime($value, $picture, $language, $calendar, $place) function returns a string containing an xs:dateTime value formatted for display.

Arguments

ArgumentType
$valuexs:dateTime
$picturexs:string
$languagexs:string
$calendarxs:string
$placexs:string
Return valuexs:string

format-integer()

This is an XPath 3.0 function, documentation follows when implemented.

format-number($value, $picture, $decimal-format-name)

The format-number($value, $picture, $decimal-format-name) function returns a string containing a number formatted according to a given picture string.

Arguments

ArgumentType
$valuenumeric
$picturexs:sring
$decimal-format-namexs:string
Return valuexs:string

Examples

format-number(12345.6, "#,###.00")"12,345.60"
format-number(0.42, "01%")"14%"
format-number(-2, "000")"-003"

format-time($value, $picture, $language, $calendar, $place)

The format-time($value, $picture) or format-time($value, $picture, $language, $calendar, $place) function returns a string containing an xs:time value.

Arguments

ArgumentType
$valuexs:time
$picturexs:string
$languagexs:string
$calendarxs:string
$placexs:string
Return valuexs:string

function-arity()

This is an XPath 3.0 function, documentation follows when implemented.

function-lookup()

This is an XPath 3.0 function, documentation follows when implemented.

function-name()

This is an XPath 3.0 function, documentation follows when implemented.

generate-id()

This is an XPath 3.0 function, documentation follows when implemented.

has-children($node)

The has-children() or has-children($node) function returns true if the supplied node has one or more child nodes. If there is no argument supplied, it defaults to the context item.

Arguments

ArgumentType
$nodenode()
Return valuexs:boolean

head()

This is an XPath 3.0 function, documentation follows when implemented.

hours-from-dateTime($arg)

The hours-from-dateTime($arg) function returns the hours component of an xs:dateTime provided by the argument.

Arguments

ArgumentType
$argxs:dateTime
Return valuexs:integer

Examples

hours-from-dateTime(xs:dateTime("2013-11-01T08:30:00-05:00"))8
hours-from-dateTime(xs:dateTime("2013-11-01T22:30:00-05:00"))22

hours-from-duration($arg)

The hours-from-duration($arg) function returns an integer that represents the hours in a by the argument provided duration.

Arguments

ArgumentType
$argxs:duration
Return valuexs:integer

Examples

hours-from-duration(xs:dayTimeDuration("P4D2H"))2
hours-from-duration(xs:dayTimeDuration("-PT32H"))-8
hours-from-duration(xs:dayTimeDuration("PT3H64M"))4
hours-from-duration(xd:dayTimeDuration("PT3H46M"))3

hours-from-time($arg)

The hours-from-time($arg) function returns the hour portion of the time provided by the argument.

Arguments

ArgumentType
$argxs:time
Return valuexs:integer

Examples

hours-from-time(xs:time("12:30:42"))12
hours-from-time(xs:time("12:30:42-05:00"))12

id($arg, $node)

The id($arg, $arg, …), $node) function returns a sequence of element nodes with an ID equal to the value of one or more $arg arguments. The $node argument is optional, if provided the function looks for elements in the same document as $node.

Arguments

ArgumentType
$argxs:string
$nodenode()
Return valueelement()

idref($arg, $node)

The idref(($arg, $arg, …), $node) function returns a sequence of element or attribute nodes that have an idref equal to the value provided by one or more $arg arguments.

Arguments

ArgumentType
$argxs:string
$nodenode()
Return valuenode()

implicit-timezone()

The implicit-timezone() function returns the implicit timezone as set by the processor. It returns an xs:dayTimeDuration value.

Arguments

This element doesn't take any arguments.

Examples

implicit-timezone()-PT5H for UTC minus 5 hours

in-scope-prefixes($element)

The in-scope-prefixes($element) function returns a sequence of prefixes that are used in the namespaces for the element provided by the $element argument.

Arguments

ArgumentType
$elementelement()
Return valuexs:string

index-of($seqParam, $srchParam, $collation)

The index-of($seqParam, $srchParam) or index-of($seqParam, $srchParam, $collation) function returns the position of an atomic value within a sequence, provided by the $seqParam argument. The $srchParam specifies the value to search for. The function will return a sequence of integers representing the positions of the value within a sequence.

Arguments

ArgumentType
$seqParamxs:anyAtomicType
$srchParamxs:anyAtomicType
$collationxs:string
Return valuexs:integer

Examples

index-of(("a", "b", "c"), "a")1
index-of(("a", "b", "c"), "d")()
index-of((1, 1), 1)(1, 2)

N.B

Don"t forget! The sequence numbering will start with 1, not 0.

innermost()

This is an XPath 3.0 function, documentation follows when implemented.

insert-before($target, $position, $inserts)

The insert-before($target, $position, $inserts) function returns a sequence constructed by inserting an item (or a sequence of items) at a by the $position argument given position in an existing sequence.

Arguments

ArgumentType
$targetitem()
$positionxs:integer
$insertsitem()
Return valueitem()

Examples

insert-before(("a", "b", "c"), 1, ("1", "2"))("1", "2", "a", "b", "c")

N.B

Don"t forget, the position numbers start at 1, not 0.

iri-to-uri($iri)

The iri-to-uri($iri) function converts a string containing an IRI into an URI. If the IRI is an empty sequence, the function will return a zero-length string.

Arguments

ArgumentType
$irixs:string
Return valuexs:string

Examples

fn:iri-to-uri ("http://frameless.io/~nénéné")"http://frameless.io/~n%C3%A9n%C3%A9n%C3%A9".

lang($testlang, $node)

The lang($testlang) or lang($testlang, $node) function tests wether the language of the context item, or by the $node argument specified node(), is the same as the by $testlang specified language. It will also check wether the language is a sublanguage of the specified language.

Arguments

ArgumentType
$testlangxs:string
$nodenode()
Return valuexs:boolean

last()

The last() function returns the context size from the dynamic context.

Arguments

This element doesn't take any arguments.

Examples

[last() -1]19

local-name-from-QName($arg)

The local-name-from-QName($arg) function returns the local part of an xs:QName. For retrieving the local part of an element or attribute name, we suggest using local-name() instead.

Arguments

ArgumentType
$argxs:QName
Return valuexs:NCName

Examples

local-name-from-QName(QName("http://frameless.io/', "number"))number
local-name-from-QName(QName("", "number"))number
local-name-from-QName(())()

local-name($arg)

The local-name() or local-name($arg) function will return the local part of the node"s name. The node may or may not be specified by the $arg argument.

Arguments

ArgumentType
$argnode()
Return valuexs:string

log($arg)

The log(num) function returns the natural logarithm of a number.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

log(100)4.605170185988092
log(1)0
log(0)-INF
log(-1)NaN

lower-case($arg)

The lower-case($arg) function converts a string, provided by the $arg argument, to lower case.

Arguments

ArgumentType
$argxs:string
Return valuexs:string

Examples

lower-case("Abc!DeF")abc!def

matches($input, $pattern, $flags)

The matches($input, $pattern) or matches($input, $pattern, $flags) function checks if the, by the $input provided, string matches the by the $pattern argument supplied regular expression. It will return true if this is the case, and will return false otherwise.

Arguments

ArgumentType
$inputxs:string
$patternxs:string
$flagsxs:string
Return valuexs:boolean

Examples

matches("frameless", "mel")true()
matches("frameless", "^f.*s$")true()
matches("frameless", "^mel")false()

max($arg, $collation)

The max($arg) or max($arg, $collation) function returns a value that is equal to the highest value appearing in the input sequence.

Arguments

ArgumentType
$argxs:anyAtomicType
$collationxs:string
Return valuexs:anyAtomicType

Examples

max((1, 2, 3, 4))4
max(("x", "y", "z"))"z"

N.B

The max() function has been implemented only for numbers, not yet for durations.

min($arg, $collation)

The min($arg) or min($arg, $collation) function returns a value that is equal to the lowest value appearing in the input sequence.

Arguments

ArgumentType
$argxs:anyAtomicType
$collationxs:string
Return valuexs:anyAtomicType

Examples

min((1, 2, 3, 4))1
min(("x", "y", "z"))"x"

N.B

The min() function has been implemented only for numbers, not yet for durations.

minutes-from-dateTime($arg)

The minutes-from-dateTime($arg) function returns the minute portion of a by the $arg argument provided xs:dateTime. The result is an integer between 0 and 59.

Arguments

ArgumentType
$argxs:dateTime
Return valuexs:integer

Examples

minutes-from-dateTime(xs:dateTime("2013-11-01T13:40:42"))40

minutes-from-duration($arg)

The minutes-from-duration($arg) function returns the minute portion of a by the $arg argument provided xs:dateTime. The result is an integer between 0 and 59.

Arguments

ArgumentType
$argxs:duration
Return valuexs:integer

Examples

minutes-from-duration(xs:duration("PT42M"))42
minutes-from-duration(xs:duration("-PT90M"))-30

minutes-from-time($arg)

The minutes-from-time($arg) function returns the minute portion of a by the $arg argument provided xs:dateTime. The result is an integer between 0 and 59.

Arguments

ArgumentType
$argxs:time
Return valuexs:integer

Examples

minutes-from-time(xs:time("10:42:21"))42

month-from-date($arg)

The month-from-date($arg) function returns the month portion of a, by the $arg provided, xs:date. It will return an integer between 1 and 12.

Arguments

ArgumentType
$argxs:date
Return valuexs:integer

Examples

month-from-date(xs:date("2013-11-01"))11

month-from-dateTime($arg)

The month-from-dateTime($arg) function returns the month portion of a, by the $arg provided, xs:dateTime. It will return an integer between 1 and 12.

Arguments

ArgumentType
$argxs:dateTime
Return valuexs:integer

Examples

month-from-dateTime(xs:dateTime("2013-11-01T10:42:21"))11

month-from-duration($arg)

The month-from-duration($arg) function returns the normalized months component of a, by the $arg provided, xs:duration. It will return an integer between -11 and 11.

Arguments

ArgumentType
$argxs:duration
Return valuexs:integer

Examples

months-from-duration(xs:yearMonthDuration("P4M"))4
months-from-duration(xs:yearMonthDuration("-P21M"))-9
months-from-duration(xs:yearMonthDuration("P12M"))0

name($arg)

The name() or name($arg) function returns the name of a node. If there is nog argument specified, it defaults to the context item.

Arguments

ArgumentType
$argnode()
Return valuexs:string

namespace-uri-for-prefix($prefix, $element)

The namespace-uri-for-prefix($prefix, $element) returns the namespace URI associated with a prefix in the scope of the specified element.

Arguments

ArgumentType
$prefixxs:string
$elementelement()
Return valuexs:anyURI

namespace-uri-from-QName($arg)

The namespace-uri-from-QName($arg) returns the namespace URI of the, by the $arg argument specified QName.

Arguments

ArgumentType
$argxs:QName
Return valuexs:anyURI

Examples

namespace-uri-from-QName(QName("http://frameless.io/index.html", "documentation"))xs:anyURI("http://frameless.io/index.html")

namespace-uri($arg)

The namespace-uri() or namespace-uri($arg) function returns the namespace URI part of the name of the, by the $arg specified, node. It will return an xs:anyURI value.

Arguments

ArgumentType
$argnode()
Return valuexs:anyURI

nilled($arg)

The nilled() or nilled($arg) function returns true if the specified element is nilled. If there is no argument, the node defaults to the context item.

Arguments

ArgumentType
$argnode()
Return valuexs:boolean

node-name($arg)

The node-name() or node-name($arg) function returns the name of the specified node as an xs:QName. If there is no argument to specify the node, it will default to the context item.

Arguments

ArgumentType
$argnode()
Return valuexs:QName

normalize-space($arg)

The normalize-space() or normalize-space($arg) function will return the value of the $arg, with leading and trailing whitespace removed and the internal whitespace reduced to single space characters.

Arguments

ArgumentType
$argxs:string
Return valuexs:string

Examples

normalize-space("Frameless distilling genuinely constructive code")"Frameless distilling genuinely constructive code"

normalize-unicode($arg, $normalizationForm)

The normalize-unicode($arg) or normalize-unicode($arg $normalizationForm) function returns the value of the by $arg specified string, after applying Unicode normalization. The $normalizationForm supports the value NFS, it defines the kind of Unicode Normalization and sets it to Unicode Normalization Form C.

Arguments

ArgumentType
$argxs:string
$normalizationFormxs:string
Return valuexs:string

Examples

normalize-unicode("frameless")frameless
normalize-unicode("£', 'NFKC")£
normalize-unicode('15 ㎗', 'NFKC')15 dl

not($arg)

The not($arg) function returns a boolean value, if the effective boolean value of $arg is false. If the effective boolean value of $arg is true, the outcome of the function will be false.

Arguments

ArgumentType
$argitem()
Return valuexs:boolean

Examples

not(true())false
not("false")false
not(0)true
not(())true
not("")true

number($arg)

The number() or number($arg) function returns the value indicated by $arg. If there is no argument specified, the context item will be used after atomisation. The value is converted to an xs:double.

Arguments

ArgumentType
$argxs:anyAtomicType
Return valuexs:double

N.B

If the $arg is the empty sequence of if the argument cannot be converted to xs:double, the value NaN is returned.

one-or-more($arg)

The one-or-more($arg) function returns the item specified by $arg if it contains one or more items. If the item doesn"t contain any items, it will throw an error (FORG0004).

Why does function even exist?

This function is not equivalent to count($arg) >= 1, because it will throw an error instead of returning false. This function could in the future be used to speed up queries because static analysis could make more assumptions about this query.

In short: don't use this function in Frameless. Yet.

Arguments

ArgumentType
$argitem()
Return valueitem()+

Examples

one-or-more(())Error FORG0004
one-or-more("a")a
one-or-more(("a", "b"))("a", "b")

outermost()

This is an XPath 3.0 function, documentation follows when implemented.

parse-xml($arg)

The parse-xml($arg) function takes an XML document represented as a string and returns the document node at the root, representing the parsed document.

Arguments

ArgumentType
$argxs:string
Return valuedocument-node(element(*))

Examples

parse-xml("world")a newly created node, with the hello element as its only child. The hello element contains a text node with the string value "world".

path($arg)

The path() or path($arg) function returns a path expression. It can be used to select the by $arg specified node, relative to the root of it"s containing document. If there is no argument specified it will default to the context item.

Arguments

ArgumentType
$argnode()
Return valuexs:string

pi()

The constant pi.

Arguments

ArgumentType
Return valuenumeric

Examples

pi()3.141592653589793

position()

The position() function returns the context position of the node that is currently being processed. The function doesn't take any arguments.

Arguments

This element doesn't take any arguments.

Examples

//book[position()<=3]selects the first three book elements

pow($arg)

The pow(num, x) function returns the number to the power x.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

pow(3, 2)9

prefix-from-QName($arg)

The prefix-from-QName($arg) function returns the prefix of the supplied xs:QName.

Arguments

ArgumentType
$argxs:QName
Return valuexs:NCName

Examples

local-name-fromQName(QName("http://frameless.io/index.html", "documentation"))"documentation"

remove($target, $position)

The remove($target, $position) function returns a new sequence containing all the items specified by $target, except the item at the position specified by the $position argument.

Arguments

ArgumentType
$targetitem()
$positionxs:integer
Return valueitem()

Examples

remove($123, 0)("1", "2", "3")
remove($123, 2)("1", "3")
remove($abc, 3)("a", "b")

replace($input, $pattern, $replacement, $flags)

The replace($input, $pattern, $replacement) or replace($input, $pattern, $replacement, $flags) function returns a new string, created by replacing any substrings that match the given regular expresion given by the $pattern argument, with the value of the $replacement argument.

Arguments

ArgumentType
$inputxs:string
$patternxs:string
$replacementxs:string
$flagsxs:string
Return valuexs:string

Examples

replace("frameless", "me", "*")"fra*less"
replace("abracadabra", "a.*a", "*")"*"
replace("AAA", "A+?", "b")"bbb"

resolve-QName($qname, $element)

The resolve-QName($qname, $element) function returns an xs:QName value by taking the value of $qname and resolve it using the in-scope namespaces of the, by $element given, element.

Arguments

ArgumentType
$qnamexs:string
$elementelement()
Return valuexs:QName

Examples

resolve-QName("Frameless", $element)returns a QName with local name "Frameless" that is in no namespace.
resolve-QName("fls:Frameless", $element)returns an xs:QName with a namespace URI specified by the namespace prefix "fls" and the local name "Frameless".

resolve-uri($relative, $base)

The resolve-uri($relative) or resolve-uri($relative, $base) function resolves a relative IRI reference against an absolute IRI.

Arguments

ArgumentType
$relativexs:string
$basexs:string
Return valuexs:anyURI

reverse($arg)

The reverse($arg) function reverses the order of items in a given sequence.

Arguments

ArgumentType
$argitem()
Return valueitem()

Examples

reverse($abc)("c", "b", "a")
reverse(("hello"))("hello")
reverse(())()

root($arg)

The root() or root($arg) function returns the root of the tree to which the node specified by $arg belongs. Usually this will be the document node, but it doesn"t have to be.

Arguments

ArgumentType
$argnode()
Return valuenode()

round-half-to-even($arg, $precision)

The round-half-to-even($arg) or round-half-to-even($arg, $precision) function rounds a value to a, by the $arg argument specified, number of decimal places. It will round to make the last digit even. The function returns the nearest value to $arg that is a multiple of ten to the power of minus $precision.

Arguments

ArgumentType
$argnumeric
$precisionxs:integer
Return valuenumeric

Examples

round-half-to-even(0.5)0.0
round-half-to-even(1.5)2.0
round-half-to-even(4231.25321, 2)4231.25
round-half-to-even(4231.123, -3)4000

round($arg, $precision)

The round($arg) or round($arg, $precision) function rounds a value to a specified number of decimal places, rounding upwards if two such values are equally near.

Arguments

ArgumentType
$argnumeric
$precisionxs:integer
Return valuenumeric

Examples

round(2.5)3.0
round(2.49)2.0
round(-1.5)-1.0
round(1.245, 2)1.25

seconds-from-dateTime($arg)

The seconds-from-dateTime($arg) function returns the seconds of the, by the $arg specified xs:dateTime.

Arguments

ArgumentType
$argxs:dateTime
Return valuexs:decimal

Examples

seconds-from-dateTime(xs:dateTime("2013-11-01T22:41:21.5"))21.5

seconds-from-duration($arg)

The seconds-from-duration($arg) function returns the number of seconds in the, by the $arg specified, duration.

Arguments

ArgumentType
$argxs:duration
Return valuexs:decimal

Examples

seconds-from-duration(xs:dayTimeDuration("P3DT2H42.5S")42.5

seconds-from-time($arg)

The seconds-from-time($arg) function returns the seconds component of the, by $arg specified, xs:time.

Arguments

ArgumentType
$argxs:time
Return valuexs:decimal

Examples

seconds-from-time(xs:time("22:42:21.5"))21.5

serialize($arg, $params)

The serialize($arg) or serialize($arg, $params) function serializes the input sequence provided by $arg, returning the serialized representation of the sequence as a string.

Arguments

ArgumentType
$argitem()
$paramselement(output:serialization-parameters)
Return valuexs:string

Examples

serialize($data, $params)"<a b='3'/>"

sin($arg)

The sin(num) return the sine of a number.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

sin(0)0
sin(pi() div 2)1

sqrt($arg)

The sqrt(num) function returns the square root of the number.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

sqrt(9)3

starts-with($arg1, $arg2, $collation)

The starts-with($arg1, $arg2) or starts-with($arg1, $arg2, $collation) function checks wether the string provided by $arg1 contains the string value of $arg2 as a leading substring. The $collation argument specifies wether collations will be taken into account.

Arguments

ArgumentType
$arg1xs:string
$arg2xs:string
$collationxs:string
Return valuexs:boolean

Examples

starts-with("frameless", "fra")true
starts-with("frameless", "less")false

static-base-uri()

The static-base-uri() function returns the value of the Static Base URI property of the static context.

Arguments

This element doesn't take any arguments.

string-join($arg1, $arg2)

The string-join($arg1) or string-join(($arg1, …), $arg2) function concatenates a sequence of strings specified by the $arg1 argument, using the optional separator specified by $arg2.

Arguments

ArgumentType
$arg1xs:string
$arg2xs:string
Return valuexs:string

Examples

string-join(("a", "b", "c"), "")abc
string-join(("a", "b", "c"), "*")a*b*c

string-length($arg)

The string-length() or string-length($arg) function returns the number of characters in the by $arg specified string. If there is no argument specified, it will return the length of the string value of the current node.

Arguments

ArgumentType
$argxs:string
Return valuexs:integer

Examples

string-length("frame")5
string-length(" frameless ")11
string-length(normalize-space(" frameless ")9

string-to-codepoints($arg)

The string-to-codepoints($arg) function returns the sequence of Unicode code points from the xs:string specified by $arg.

Arguments

ArgumentType
$argxs:string
Return valuexs:integer

Examples

string-to-codepoints("abc")(97, 98, 99)
string-to-codepoints("a")(97)
string-to-codepoints("")()

string($arg)

The string() or string($arg) function returns the value of the xs:string specified by $arg. If there is no argument specified, the function will default to the context item.

Arguments

ArgumentType
$argxs:string
Return valuexs:string

Examples

string(42)"42"
string(true())"true"
string(abc#1)Error FOTY0014
string("abc#1")"abc#1"

subsequence($sourceSeq, $startingLoc, $length)

The subsequence($sourceSeq, $startingLoc) or subsequence($sourceSeq, $startingLoc, $length) function returns a portion of the $sourceSeq sequence, based on a starting point specified by $startingLoc. If specified the portion that is returned has the length specified by $length.

Arguments

ArgumentType
$sourceSeqitem()
$startingLocxs:double
$lengthxs:double
Return valueitem()

Examples

subsequence (("a", "b", "c", "d", "e", "f"), 3)("c", "d", "e", "f")
subsequence ("a", "b", "c", "d", "e", "f"), 3, 2)("c","d")

substring-after($arg1, $arg2, $collation)

The substring-after($arg1, $arg2) or substring-after($arg1, $arg2, $collation) function returns the part of the $arg1 string that follows the first occurrence of $arg2. The $collations attribute specifies if collations should be taken into account.

Arguments

ArgumentType
$arg1xs:string
$arg2xs:string
$collationxs:string
Return valuexs:string

Examples

substring-after("frameless", "frame")"less"
substring-after("frameless", "less")""

substring-before($arg1, $arg2, $collation)

The substring-before($arg1, $arg2) or substring-before($arg1, $arg2, $collation) function returns the part of the $arg1 string that precedes the first occurrence of $arg2. The $collations attribute specifies if collations should be taken into account.

Arguments

ArgumentType
$arg1xs:string
$arg2xs:string
$collationxs:string
Return valuexs:string

Examples

substring-before("frameless", "frame")""
substring-before("frameless", "less")"frame"

substring($sourceString, $start, $length)

The substring($sourceString, $start) or substring($sourceString, $start, $length) function returns a new string based on the value of $sourceString, but beginning at the position indicated by $start and continuing for the number of characters specified by $length. If there is no $length argument, it will continue until the end of the $sourceString value.

Arguments

ArgumentType
$sourceStringxs:string
$startxs:double
$lengthxs:double
Return valuexs:string

Examples

substring("frameless processor", 5)"less processor"
substring("frameless processor", 1, 9)"frameless"

sum($arg, $zero)

The sum($arg) or sum($arg, $zero) function returns a value obtained by adding together the functions specified by $arg. The $zero argument allows you to specify an alternate value for the sum of the empty sequence.

Arguments

ArgumentType
$argxs:anyAtomicType
$zeroxs:anyAtomicType
Return valuexs:anyAtomicType

Examples

sum((1,2,3))6
sum(())0
sum((),())()

N.B

Implemented, but only for numbers, not for durations

tail()

This is an XPath 3.0 function, documentation follows when implemented.

tan($arg)

The tan(num) return the tangent of a number.

Arguments

ArgumentType
$argnumeric
Return valuenumeric

Examples

tan(0)0

timezone-from-date($arg)

The timezone-from-date($arg) function returns the timezone component of the xs:date specified by $arg.

Arguments

ArgumentType
$argxs:date
Return valuexs:dayTimeDuration

Examples

timezone-from-date(xs:date("2013-11-01-08:00"))xs:dayTimeDuration("-PT8H")

timezone-from-dateTime($arg)

The timezone-from-dateTime($arg) function returns the timezone component of the, by $arg specified xs:dateTime.

Arguments

ArgumentType
$argxs:dateTime
Return valuexs:dayTimeDuration

Examples

timezone-from-dateTime(xs:dateTime("2013-11-01T22:42:21-08:00")xs:dayTimeDuration("-PT8H")

timezone-from-time($arg)

The timezone-from-time($arg) function returns the timezone component of the xs:time specified by $arg.

Arguments

ArgumentType
$argxs:time
Return valuexs:dayTimeDuration

Examples

timezone-from-time(xs:time("22:42:21-08:00"))xs:dayTimeDuration("-PT8H")

tokenize($input, $pattern, $flags)

The tokenize($input, $pattern) or tokenize($input, $pattern, $flags) function splits the string provided by $input, based on the regular expression provided by $pattern.

Arguments

ArgumentType
$inputxs:string
$patternxs:string
$flagsxs:string
Return valuexs:string

Examples

tokenize("abc", "\s")("a", "b", "c")
tokenize("a bc", "\s")("a", "", "b", "c")

trace($value, $label)

The trace($value, $label) function provides an execution trace intended to be used in debugging queries.

Arguments

ArgumentType
$valueitem()
$labelxs:string
Return valueitem()

N.B

When console.log is available this function will log there. If the second argument is used, window[message] (if it is not set already) will have a debuggin scope available.

translate($arg, $mapString, transString)

The translate($arg, $mapString, $transString) function returns the value of the string provided by $arg, modified by replacing or removing individual characters.

Arguments

ArgumentType
$argxs:string
$mapStringxs:string
transStringxs:string
Return valuexs:string

Examples

translate("bar", "abc", "ABC")Bar
translate("-aaa-", "abc-", "ABC")"AAA"

true()

The true() function is used for constructing the boolean value true. It doesn"t take any arguments and is used in XPath instead of the keyword true. It"s counterpart is false().

Arguments

This element doesn't take any arguments.

Examples

true()true

unordered($sourceSeq)

The unordered($sourceSeq) function returns items specified by $sourceSeq.

Arguments

ArgumentType
$sourceSeqitem()
Return valueitem()

Examples

unordered((1, 2, 3, 4, 5))(1, 2, 3, 4, 5)

unparsed-entity-public-id()

Not implemented. DTDs are not supported.

unparsed-entity-uri()

Not implemented. DTDs are not supported.

unparsed-text-available($href, $encoding)

The unparsed-text-available($href) or unparsed-text-available($href, $encoding) function allows an application to determine whether a call with particular arguments would succeed.

Arguments

ArgumentType
$hrefxs:string
$encodingxs:string
Return valuexs:boolean

unparsed-text-lines($href, $encoding)

The unparsed-text-lines($href) or unparsed-text-lines($href, $encoding) function reads an external source provided by the $href attribute and returns it"s contents as a sequence of strings, one for each line of text in the string representation of the resource.

Arguments

ArgumentType
$hrefxs:string
$encodingxs:string
Return valuexs:string

unparsed-text($href, $encoding)

The unparsed-text($href) or unparsed-text($href, $encoding) function reads an external resource, provided by $href and returns a string representation of the resource.

Arguments

ArgumentType
$hrefxs:string
$encodingxs:string
Return valuexs:string

upper-case($arg)

The upper-case($arg) function converts a string to upper case.

Arguments

ArgumentType
$argxs:string
Return valuexs:string

Examples

upper-case("abCd0")"ABCD0"

uri-collection()

No use in the context of the browser. Always returns the empty sequence.

year-from-date($arg)

The year-from-date($arg) function returns the year component of the xs:date provided by $arg.

Arguments

ArgumentType
$argxs:date
Return valuexs:integer

Examples

year-from-date(xs:date("2013-11-01"))2013
year-from-date(xs:date("2013-11-01+-08:00"))2013

year-from-dateTime($arg)

The year-from-dateTime($arg) function returns the year component of the xs:dateTime provided by $arg.

Arguments

ArgumentType
$argxs:dateTime
Return valuexs:integer

Examples

year-from-dateTime(xs:dateTime("2013-11-01T22:42:21-08:00"))2013

years-from-duration($arg)

The years-from-duration($arg) function returns the number of years in a duration, provided by the $arg argument.

Arguments

ArgumentType
$argxs:duration
Return valuexs:integer

Examples

years-from-duration(xs:yearMonthDuration("P20Y16M"))21
years-from-duration(xs:yearMonthDuration("-P16M"))-1

zero-or-one($arg)

The zero-or-one($arg) function returns the content of $arg, if it contains zero or one items. If it contains more than one item, it will throw an error (FORG0003).

Why does function even exist?

This function is not equivalent to count($arg) = (0, 1), because it will throw an error instead of returning false. This function could in the future be used to speed up queries because static analysis could make more assumptions about this query.

In short: don't use this function in Frameless. Yet.

Arguments

ArgumentType
$argitem()
Return valueitem()

Examples

zero-or-one(())()
zero-or-one("hello")"hello"
zero-or-one(("hello", "world"))Error FORG0003

JavaScript versus XPath

If you know JavaScript well and just started using XPath for finding and filtering data, here's a mapping of various JavaScript operations to their XPath counterparts. If there's anything missing here contact us or send out a tweet to @frameless_io.

We're working on such an overview for CSS selectors as well.

Booleans

JavaScript XPath
true true()
false false()
!something not($something)
!!something boolean($something)

Type conversions

JavaScript XPath
Boolean("true") boolean("true")
String(42) string(42)
Number("42") number("42")
obj.toString() string($obj)

Math

JavaScript XPath
Math.min(x, y) min(($x, $y))
Math.min(x, Math.min(y, z)) min(($x, $y, $z))
Math.max(x, y) max(($x, $y))
Math.abs(x) abs($x)
Math.ceil(x) ceiling($x)
Math.floor(x) floor($x)
Math.round(x) round($x)
Math.exp(x) exp($x)
Math.pow(x, y) pow($x, $y)
Math.log(x) log($x)
Math.sqrt(x) sqrt($x)
Math.sin(x) sin($x)
Math.cos(x) cos($x)
Math.tan(x) tan($x)
Math.asin(x) asin($x)
Math.acos(x) acos($x)
Math.atan(x) atan($x)
Math.atan2(x, y) atan2($x, $y)

Arithmetic

JavaScript XPath
1 + 1 1 + 1
1 - 1 1 - 1
1 * 1 1 * 1
1 / 1 1 div 1
1 % 2 1 mod 2
Infinity INF
-Infinity -INF
NaN NaN
-0 -0

Strings

JavaScript XPath
"Hello " + $world "Hello " || $world
str.length string-length($str)
str.charCodeAt(0) string-to-codepoints($str)[1]
list.join('-') string-join($list, '-')
str.replace(pattern, x) replace($str, $pattern, $x)
str.toUpperCase() upper-case($str)
str.toLowerCase() lower-case($str)
str.indexOf(x) !== -1 contains($str, $x)
str.substring(...) starts-with($str, $x),

ends-with($str, $x),

substring-before($str, $x),

substring-after($str, $x)
str.split(',') tokenize($str, $pattern)

DOM methods and properties

JavaScript XPath
nodeA === nodeB $nodeA is $nodeB
a.parentNode === b $b[$a]
getElementById("nav") id('nav')
getElementsByTagName("*") //*
getElementsByTagName("p") //p
getElementsByTagNameNS("http://www.w3.org/2000/svg", "*") //svg:*
getElementsByTagNameNS("http://www.w3.org/2000/svg", "rect") //svg:rect
Node.childNodes node()
Node.childNodes.length count(node())
Node.firstElementChild *[1]
Node.lastElementChild *[last()]
Node.childElementCount count(*)
Node.previousElementSibling preceding-sibling::*[1]
Node.nextElementSibling following-sibling::*[1]
Node.parentElement parent::*
Node.firstChild node()[1]
Node.lastChild node()[last()]
Node.nextSibling following-sibling::node()[1]
Node.previousSibling preceding-sibling::node()[1]
Node.textContent string(.)
Node.ownerDocument /

root($node) (for connected nodes)
Node.parentNode ..
Node.hasChildNodes() node() or exists(node())
Document.URL base-uri(/)
Node.baseURI base-uri()
Node.lookupPrefix lookup-prefix()
Node.lookupNamespaceURI('svg') namespace-uri-for-prefix('svg')
Node.isEqualNode($b) deep-equals($a, $b)
Node.nodeName node-name()
Node.nodeType === Node.ELEMENT_NODE self::*
Node.nodeType === Node.TEXT_NODE ||

Node.nodeType === Node.CDATA_SECTION_NODE
self::text()
Node.nodeType === Node.PROCESSING_INSTRUCTION_NODE self::processing-instruction()
Node.nodeType === Node.COMMENT_NODE self::comment()
Node.nodeType === Node.DOCUMENT_NODE self::document-node()
Element.localName local-name()
Element.namespaceURI namespace-uri()
Element.id @id or @xml:id
Element.prefix prefix()
Element.tagName name()
Element.attributes @*
Element.getAttribute("href") @href
Element.getAttributeNS("http://www.w3.org/1999/xlink", "href") @xlink:href
Element.matches('p') self::p
Element.matches('a[href]') self::a[@href]
Element.query('form') .//form[1]
Element.queryAll('form') .//form
Attr.name name(@href)
Attr.prefix prefix(@xlink:href)
Attr.localName local-name(@xlink:href)
Attr.namespaceURI namespace-uri(@xlink:href)
Attr.value string(@href)
Attr.ownerElement ..

Date

JavaScript XPath
new Date current-dateTime()
date.getDate() day-from-dateTime($date) Day of month (e.g: 1 - 31)
date.getFullYear() year-from-dateTime($date) Year (e.g: 2004)
date.getHours() hours-from-dateTime($date) Hour of day (0 - 23)
date.getMinutes() minutes-from-dateTime($date) Minute in hour (0 - 59)
date.getSeconds() seconds-from-dateTime($date) Second in minute (0 - 59)
date.toISOString() string($date) Date in ISO8601 format, e.g: "2013-11-25T15:24:16.370+01:00"

Various

JavaScript XPath
location.href static-base-uri()
new Date().getTimezoneOffset() implicit-timezone()

Known issues

XSLT processor

The software is currently in beta, we're still working on supporting more features of XSLT 2.0

Compatibility with Saxon-CE

For convience Frameless has

XSLTProcessor method browser Frameless Saxon-CE
importStylesheet() yes yes yes
transformToDocument() yes yes yes
transformToFragment() yes yes yes
getParameter() yes yes yes
removeParameter() yes yes yes
setParameter() yes yes yes
reset() yes yes yes
clearParameters() no yes yes
getInitialMode() no yes yes
setInitialMode() no yes yes
getInitialTemplate() no yes yes
setInitialTemplate() no yes yes
getSuccess() no yes yes
setSuccess() no yes yes
getResultDocument() no yes yes
getResultDocuments() no yes yes
setBaseOutputURI() no no yes
transformToHTMLFragment() no no yes
updateHTMLDocument() no no yes

Differences between Frameless and Saxon-CE

Technical differences

Frameless is an XSLT processor developed natively in JavaScript. It's architecture is designed around JavaScript best practices for performance, cross-browser compatibility and code size. For asynchronous operations it works with de-facto standards such as AMD modules and Promises.

Saxon-CE is written in Java and cross-compiled to JavaScript using GWT. The implementation builds on a robust XSLT 2.0 implementation that already fully conforms to the XSLT 2.0 specification, whereas Frameless still sees improvements in conformance every day.

The script element

The <script> element doesn't require language attribute, where as in Saxon-CE it does.

method name browser XSLTProcessor Frameless XSLT2Processor
importStylesheet() yes yes
transformToDocument() yes yes
transformToFragment() yes yes
getParameter() yes yes
removeParameter() yes yes
setParameter() yes yes
reset() yes yes

Asynchronous loading of the processor

Instead of the onSaxonLoad function Frameless uses the widely accepted AMD modules: require(['frameless-xslt2']). Using asynchronous loading requires including any third party library that supports AMD modules, such as RequireJS or Curl.