# New and Changed Extension Functions

Two new extension functions `saxon:index` and `saxon:find` are available. These are particularly useful in XQuery, where they provide an equivalent to the capability offered by `xsl:key` in XSLT. The functions can also be useful in XSLT, because unlike `xsl:key` they allow any sequence to be indexed, even one that spans multiple documents. The typical usage is first to create an indexed sequence, for example by:

`declare variable $indexedTowns := saxon:index(//town, saxon:expression("@state"));`

and then to retrieve towns whose state is known by using `saxon:find()`:

`{ saxon:find($indexedTowns, "MA") }`

This example finds all `<town>` elements whose `state` attribute has the value `MA`.

These extension functions are available only in Saxon-SA.

If the argument to the function `saxon:expression` is a compile-time constant (typically a string literal), then the XPath expression is compiled at stylesheet compile time and any errors are reported as static errors.

Expand | Up Next