Skip to content
XSLT Functions

XSLT Functions

These functions are only available during XSLT transformation (not in standalone XPath evaluation).

key

key($name as xs:string, $value as xs:anyAtomicType) as node()*

key($name as xs:string, $value as xs:anyAtomicType, $top as node()) as node()*

Looks up nodes indexed by xsl:key. The 3-argument form restricts the search to the document containing $top.

<xsl:key name="id" match="item" use="@id"/>

<xsl:value-of select="key('id', 'A42')/@name"/>

document

document($uri as xs:string) as document-node()

Loads an external XML document. Results are cached. Use document('') to access the stylesheet document itself.

id

id($value as xs:string) as element()*

id($value as xs:string, $node as node()) as element()*

Finds elements with a matching xml:id attribute. Space-separated values in $value are treated as multiple IDs.

current

current() as item()

Returns the current item being processed by xsl:apply-templates or xsl:for-each. Unlike ., this remains stable inside predicates.

generate-id

generate-id() as xs:string

generate-id($node as node()) as xs:string

Returns a unique identifier string for a node, stable across calls.

regex-group

regex-group($group as xs:integer) as xs:string

Returns the captured group from the current regex match inside xsl:matching-substring of xsl:analyze-string.

<xsl:analyze-string select="'2024-01-15'" regex="(\d{{4}})-(\d{{2}})-(\d{{2}})">
  <xsl:matching-substring>
    Year: <xsl:value-of select="regex-group(1)"/>
  </xsl:matching-substring>
</xsl:analyze-string>

current-group

current-group() as item()*

Returns all items in the current group inside xsl:for-each-group.

current-grouping-key

current-grouping-key() as xs:anyAtomicType

Returns the grouping key for the current group inside xsl:for-each-group.

unparsed-text

unparsed-text($href as xs:string) as xs:string

Reads a text file and returns its content as a string. Relative URIs are resolved against the stylesheet location.

<xsl:variable name="data" select="unparsed-text('data.csv')"/>

unparsed-text-available

unparsed-text-available($href as xs:string) as xs:boolean

Returns true if the file at $href exists and can be read.