michal.kreuzman
michal.kreuzman

Reputation: 12390

Create XPath function in XSLT 1.0

I'm looking how to create my own XPath function in XSLT-1.0. For example I have simple XPath expression which I'm using again and again in my XSLT template. I want to create my own XPath function myOwnFunction($var) which calls XPath expression.

Example expression:

normalize-space(substring-after(substring-after($var, '-'), '-'))

Upvotes: 7

Views: 5920

Answers (3)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

The previous two answers said it all: XSLT 1.0 does not provide the means to create functions that can be referenced from within an XPath expression.

If someone wants such functionality they should start using XSLT 2.0 (and make use of the standard <xsl:function> instruction), or:

  • Use the <func:function> extension element provided by EXSLT. Note that very few XSLT 1.0 processors implement this extension element.

  • Use a particular XSLT processor feature, if such exists. For the .NET platform one can use the XsltContext class, the IXsltContextFunction interface and techniques like this.

Anyway, all this is not at all XSLT programming, so my advice is to start using XSLT 2.0 seriously.

Upvotes: 11

Flack
Flack

Reputation: 5892

If you are stuck with 1.0, you can check if your processor supports EXSLT Functions.

Upvotes: 5

Dark Falcon
Dark Falcon

Reputation: 44181

XSLT 1.0 does not define this functionality. It was added in XSLT 2.0. You'll either have to use 2.0 or use some implementation-specific means to do this.

Upvotes: 4

Related Questions