开发者

Replacement of <xsl:eval> and <xsl:script> in XSL

开发者 https://www.devze.com 2023-02-01 07:36 出处:网络
I am trying to modify an xsl which is of the older version. I come across the following: <xsl:eval>FormatAccount(this)</xsl:eval>

I am trying to modify an xsl which is of the older version. I come across the following:

<xsl:eval>FormatAccount(this)</xsl:eval>

<xsl开发者_开发技巧:script>
    function FormatAccount(e) {
       // function details
    }
</xsl:script>

I am trying to call the FormatAccount() javascript function using <xsl:eval> and the function is written in <xsl:script>.

How to do this as per the latest standards?


The latest standard is XSLT 2.0 http://www.w3.org/TR/xslt20/, it does not have any facility to define functions in Javascript, it however allows you to define functions with XSLT itself: http://www.w3.org/TR/xslt20/#stylesheet-functions. XSLT 2.0 is supported by XSLT 2.0 processors like Saxon 9 http://saxon.sourceforge.net/, AltovaXML Tools http://www.altova.com/altovaxml.html or XQSharp http://www.xqsharp.com/xqsharp/beta.htm.

If you want to use Javascript to define extension functions we need to know which XSLT processor you use, of those three XSLT 2.0 processors I mentioned I think only AltovaXML Tools allows that (http://manual.altova.com/AltovaXML/altovaxmlcommunity/index.html?xextmsxsl.htm), and only, I think, to allow easier migration of XSLT 1.0 stylesheets written for Microsoft MSXML.

If you want to use an XSLT 1.0 processor then there too defining extension functions in a particular programming language like Javascript depends on the processor you use, for MSXML there is an msxsl:script element: http://msdn.microsoft.com/en-us/library/ms256042.aspx.


Embedded extension functions in other language is not the content model of XSLT.

Extension elements and extension functions are part of the content model as described in http://www.w3.org/TR/xslt#extension : it's implementation dependant how exactly an XSLT processor register those extensions.

As pointed by @Martin Honnen's answer, in XSLT 2.0 you can declare "stylesheet functions" with XSLT itself.

0

精彩评论

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