{"id":36600510,"url":"https://github.com/expath/expath-tools-saxon","last_synced_at":"2026-01-12T08:37:46.946Z","repository":{"id":49105252,"uuid":"184625120","full_name":"expath/expath-tools-saxon","owner":"expath","description":"Common Saxon Tools for EXPath Implementations","archived":false,"fork":false,"pushed_at":"2024-06-28T15:46:56.000Z","size":3893,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-06-28T17:12:58.805Z","etag":null,"topics":["expath","saxon"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/expath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-02T17:44:09.000Z","updated_at":"2024-06-28T15:46:59.000Z","dependencies_parsed_at":"2024-06-28T17:22:57.422Z","dependency_job_id":null,"html_url":"https://github.com/expath/expath-tools-saxon","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/expath/expath-tools-saxon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expath%2Fexpath-tools-saxon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expath%2Fexpath-tools-saxon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expath%2Fexpath-tools-saxon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expath%2Fexpath-tools-saxon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/expath","download_url":"https://codeload.github.com/expath/expath-tools-saxon/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expath%2Fexpath-tools-saxon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28337599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expath","saxon"],"created_at":"2026-01-12T08:37:45.974Z","updated_at":"2026-01-12T08:37:46.933Z","avatar_url":"https://github.com/expath.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EXPath Tools for Saxon\n\n[![Build Status](https://github.com/expath/expath-tools-saxon/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/expath/expath-tools-saxon/actions/workflows/ci.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/org.expath.tools/tools-saxon.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22org.expath.tools%22%20AND%20a:%22tools-saxon%22)\n[![License](https://img.shields.io/badge/license-MPL%201.0-blue.svg)](https://opensource.org/licenses/MPL-1.0)\n\nImplementation of the tools for Saxon.\n\nIt is mainly two things now: the implementation of the data model from\ntools-java, and additional tools to ease writing extension functions for Saxon.\n\nFunction tools\n--------------\n\nA good example of the API for extension functions is the project `file-saxon`,\nimplementing the EXPath [File module](http://expath.org/spec/file), in the\nrepository [expath-file-java](https://github.com/fgeorges/expath-file-java).\n\nLet us have a look for instance at the class\n[Exists](https://github.com/fgeorges/expath-file-java/blob/master/file-saxon/src/org/expath/file/saxon/props/Exists.java):\n\n```java\npublic class Exists\n        extends Function\n{\n    public Exists(Library lib)\n    {\n        super(lib);\n    }\n\n    @Override\n    protected Definition makeDefinition()\n            throws ToolsException\n    {\n        return library()\n                .function(this, LOCAL_NAME)\n                .returns(Types.SINGLE_BOOLEAN)\n                .param(Types.SINGLE_STRING, PARAM_PATH)\n                .make();\n    }\n\n    @Override\n    public Sequence call(XPathContext ctxt, Sequence[] orig_params)\n            throws XPathException\n    {\n        // the params\n        Parameters params = checkParams(orig_params);\n        String path = params.asString(0, false);\n        // the actual call\n        Properties props = new Properties();\n        boolean res = props.exists(path);\n        return Return.value(res);\n    }\n\n    private static final String LOCAL_NAME = \"exists\";\n    private static final String PARAM_PATH = \"path\";\n}\n```\n\nWe can see interesting points:\n\n- an extension function extends the class [Function](https://github.com/expath/tools-saxon/blob/master/tools-saxon/src/org/expath/tools/saxon/fun/Function.java)\n- its constructor takes a [Library](https://github.com/expath/tools-saxon/blob/master/tools-saxon/src/org/expath/tools/saxon/fun/Library.java) object\n- the library is available through the `library()` method\n- it implements one method to return the function definition (describing its signature)\n- it implements a second method to actually implement the function behaviour\n- it uses several tools to deal with type descriptions, type conversions, parameters, etc.\n\n**Type description**\n\nThe class\n[Types](https://github.com/expath/tools-saxon/blob/master/tools-saxon/src/org/expath/tools/saxon/fun/Types.java)\ncontains static variables for all item types and sequence types, using a\nconsistent naming scheme.  For instance `xs:integer+` is `SEVERAL_INTEGER`, and\n`element()?` is `OPTIONAL_ELEMENT`.\n\nIt also contains methods to construct more complex item types like\n`element(name)`, which would be: `singleElement(\"name\", saxon)` (requires the\nSaxon processor object).\n\n**Function definition**\n\nThe function definition is described through a utility class,\n[Definition](https://github.com/expath/tools-saxon/blob/master/tools-saxon/src/org/expath/tools/saxon/fun/Definition.java).\nThis class implements the Saxon's abstract class for function definitions,\n`ExtensionFunctionDefinition`, based on values passed to its constructor.  But\nyou never use it directly, you construct a definition by using a builder object,\nitself instantiated by the method `Library.function()`.  You add the local name,\nreturn type, parameters, and then ask for the definition object.\n\nGiven the following example function (yes, there are 3 different functions, all\nwith the same name, with different arities, which Saxon represents with the same\nfunction definition object):\n\n```\nmy:hello() as xs:string\nmy:hello($name as xs:string) as xs:string\nmy:hello($name as xs:string, $lang as xs:string*) as xs:string\n```\n\nThis function can be describe by the following code (assuming you already have a\nlibrary object for this library, with the namespace URI and prefix):\n\n```java\nlibrary()\n    .function(this, \"hello\")\n    .returns(Types.SINGLE_STRING)\n    .optional()\n    .param(Types.SINGLE_STRING, \"name\")\n    .param(Types.ANY_STRING, \"lang\")\n    .make();\n```\n\n**Parameters**\n\nThe class\n[Parameters](https://github.com/expath/tools-saxon/blob/master/tools-saxon/src/org/expath/tools/saxon/fun/Parameters.java)\nprovides helpers for dealing with Saxon's raw parameters.  In particular, it\nhelps accessing one specific parameter as a generic Java type, given its\npositional number.  It reports the parameter name in the error message in case\nof an error.  For instance (assuming the parameter is not optional):\n\n```java\nString path = params.asString(0, false);\n```\n\n**Return values**\n\nThe class\n[Return](https://github.com/expath/tools-saxon/blob/master/tools-saxon/src/org/expath/tools/saxon/fun/Return.java)\nis like the class\n[Parameters](https://github.com/expath/tools-saxon/blob/master/tools-saxon/src/org/expath/tools/saxon/fun/Parameters.java),\nbut the other way around: it returns a Saxon sequence object from a java generic\nobject.  For instance, this will return an `xs:boolean`:\n\n```java\nreturn Return.value(true);\n```\n\n**Library**\n\nA library represents a set of functions in the same namespace.  It contains a\nnamespace URI, a namespace prefix, a set of functions and a way to create Saxon\nXPath errors (based on code names, typically bound to exceptions).  The namespace\nprefix is used every time a function or error name has to be presented to the\nuser, as in error messages.  It looks typically like this (look at this example,\n[EXPathFileLibrary](https://github.com/fgeorges/expath-file-java/blob/master/file-saxon/src/org/expath/file/saxon/EXPathFileLibrary.java)):\n\n```java\npublic class SomeLibrary\n        extends Library\n{\n    public SomeLibrary()\n    {\n        super(NS_URI, NS_PREFIX);\n    }\n\n    @Override\n    protected Function[] functions()\n            throws ToolsException\n    {\n        return new Function[] {\n            new SomeFunction(this),\n            new AnotherFunction(this),\n            new YetAnotherOne(this)\n        };\n    }\n\n    public XPathException error(SomeException ex)\n    {\n        switch ( ex.getType() ) {\n            case NOT_FOUND:\n                return error(ERR_NOT_FOUND, ex.getMessage(), ex);\n            case FOOBAR:\n                return error(ERR_FOOBAR, ex.getMessage(), ex);\n            default:\n                return error(ERR_DEFAULT, ex.getMessage(), ex);\n        }\n    }\n\n    public static final String NS_URI    = \"http://example.org/ns/my-library\";\n    public static final String NS_PREFIX = \"my\";\n\n    // error codes, my:not-found, my:foobar and my:default-error\n    private static final String ERR_NOT_FOUND = \"not-found\";\n    private static final String ERR_FOOBAR    = \"foobar\";\n    private static final String ERR_DEFAULT   = \"default-error\";\n}\n```\n\nGiven a library object, all the functions it contains can be registered against\na Saxon `Configuration` object.  This object is available regardless of the\nSaxon API you use.  For instance, using S9API's `Processor`:\n\n```java\n// the Saxon objects\nProcessor saxon = ...;\nConfiguration config = saxon.getUnderlyingConfiguration();\n// the library\nLibrary lib = new SomeLibrary();\nlib.register(config);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpath%2Fexpath-tools-saxon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpath%2Fexpath-tools-saxon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpath%2Fexpath-tools-saxon/lists"}