开发者

Create XPath function in XSLT 1.0

开发者 https://www.devze.com 2023-02-16 05:38 出处:网络
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 my

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:

normaliz开发者_开发技巧e-space(substring-after(substring-after($var, '-'), '-'))


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号