PHPackages                             carica/xpath-functions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. carica/xpath-functions

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

carica/xpath-functions
======================

Provides XPath 2/3 like functions for PHPs ext/xslt

00PHP

Since Nov 23Pushed 3y agoCompare

[ Source](https://github.com/ThomasWeinert/Carica-XPath-Functions)[ Packagist](https://packagist.org/packages/carica/xpath-functions)[ RSS](/packages/carica-xpath-functions/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Carica XPath Functions
======================

[](#carica-xpath-functions)

This is project tries to add [Xpath 2/3 functions](https://www.w3.org/TR/xpath-functions-31) to PHPs XSLTProcessor. A complete implementation isn't possible - some of the syntax is not available. But let's see how much can be done.

If you have a function that you would like to have added please open an issue.

How it works:
-------------

[](#how-it-works)

- Extends the `XSLTProcessor` with `Carica\XpathFunctions\XSLTProcessor`
- Implements a callback for the XSLTProcessor to call specific PHP functions
- Adds a stream wrapper to load XSLT templates that wrap callbacks to PHP as Xpath functions using EXSLT or implement the function directly.

Install
=======

[](#install)

`composer require carica/xpath-functions`

Usage
=====

[](#usage)

1. Define the namespace for the function
2. Import a module into your XSLT
3. Call the Xpath function

Step 2 is the difference to XSLT 2/3. You need to import the module template with the functions you would like to use.

Compromises
-----------

[](#compromises)

Xpath/XSLT 1.0 does not of the extensive type system of their successors. So most of the functions return more basic types. Arrays and maps are emulated with XDM nodes, sequences as XDM arrays.

Examples
--------

[](#examples)

### Use String Comparsion

[](#use-string-comparsion)

```
// import extended XSLTProcessor
use Carica\XpathFunctions\XSLTProcessor;

$xslt =

      Exactly
      André

      Case Insensitive, Ignore Accents
      Andre
      André
      Andrè

```

### Wrap Parts Of Text Nodes Using RegExp

[](#wrap-parts-of-text-nodes-using-regexp)

```
// import extended XSLTProcessor
use Carica\XpathFunctions\XSLTProcessor;

$xslt =
The test number is 123456789, and some further block of text.
```

Implemented Functions
---------------------

[](#implemented-functions)

FunctionNotes**Context**fn:current-dateTime()fn:current-date()fn:current-time()fn:implicit-timezone()fn:default-collation()fn:default-language()**DateTime/Components**fn:dateTime()fn:year-from-dateTime()fn:month-from-dateTime()fn:day-from-dateTime()fn:hours-from-dateTime()fn:minutes-from-dateTime()fn:seconds-from-dateTime()fn:timezone-from-dateTime()fn:year-from-date()fn:month-from-date()fn:day-from-date()fn:hours-from-time()fn:minutes-from-time()fn:seconds-from-time()fn:timezone-from-time()**DateTime/TimezoneAdjust**fn:adjust-dateTime-to-timezone()fn:adjust-date-to-timezone()fn:adjust-time-to-timezone()**Duration/Components**fn:years-from-duration()fn:months-from-duration()fn:days-from-duration()fn:hours-from-duration()fn:minutes-from-duration()fn:seconds-from-duration()**Errors**fn:error()expects URI as first argument (not QName)**MapsAndArrays/Arrays**array:array()replacement for `[]` syntax, max 10 argumentsarray:size()array:get()array:put()array:append()array:subarray()array:remove()array:insert-before()max 10 item argumentsarray:head()array:tail()array:join()up to 10 array argumentsarray:reverse()array:flatten()**MapsAndArrays/JSON**fn:parse-jsonreturns document element from fn:json-to-xml()fn:json-docfn:json-to-xmlwithout optionsfn:xml-to-jsonwithout options, ignores namespace**MapsAndArrays/Maps**map:map()replacement for `{}` syntax, max 10 argumentsmap:size()map:keys()map:contains()map:get()map:put()map:remove()map:find()map:entry()**Numeric/Formatting**fn:format-integer()partially**Numeric/Math**math:pi()math:exp()math:exp10()math:log()math:log10()math:pow()math:sqrt()math:sin()math:cos()math:tan()math:asin()math:acos()math:atan()math:atan2()**Numeric/Values**fn:round-half-to-even()**Sequences/Cardinality**fn:zero-or-one()fn:one-or-more()fn:exactly-one()**Sequences/External**fn:unparsed-text()no relative url resolving, basic encoding handlingfn:unparsed-text-lines()no relative url resolving, basic encoding handling**Sequences/Operations**fn:empty()fn:head()fn:tail()fn:insert-before()max 10 item argumentsfn:remove()fn:reverse()fn:subsequence()**Sequences/Parse**fn:parse-xml()fn:parse-xml-fragment()**Strings/Comparsion**fn:compare()fn:codepoint-equal()fn:collation-key()fn:contains-token()**Strings/Values**fn:upper-case()fn:lower-case()**Strings/RegExp**fn:matches()fn:replace()fn:tokenize()fn:analyze-string()

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/236825?v=4)[Thomas Weinert](/maintainers/ThomasWeinert)[@ThomasWeinert](https://github.com/ThomasWeinert)

---

Top Contributors

[![ThomasWeinert](https://avatars.githubusercontent.com/u/236825?v=4)](https://github.com/ThomasWeinert "ThomasWeinert (77 commits)")

### Embed Badge

![Health badge](/badges/carica-xpath-functions/health.svg)

```
[![Health](https://phpackages.com/badges/carica-xpath-functions/health.svg)](https://phpackages.com/packages/carica-xpath-functions)
```

###  Alternatives

[h5p/h5p-editor

H5P Editor functionality in PHP

761.5M29](/packages/h5p-h5p-editor)[petrgrishin/array-map

The object oriented approach to working with arrays on PHP

125.8k1](/packages/petrgrishin-array-map)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
