Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, '-'), '-'))
like image 982
michal.kreuzman Avatar asked Mar 09 '11 13:03

michal.kreuzman


3 Answers

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.

like image 88
Dimitre Novatchev Avatar answered Sep 19 '22 01:09

Dimitre Novatchev


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

like image 29
Flack Avatar answered Sep 21 '22 01:09

Flack


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.

like image 44
Dark Falcon Avatar answered Sep 22 '22 01:09

Dark Falcon