Jump to content

Embedding Scripts In Xslt


Recommended Posts

Hi ! I have to call an external function in my xslt/xsl-fo stylesheet. I know that I can use <xsl:script> according to the recommendation (http://www.w3.org/TR/xslt11/#define-extension-functions) The question is how to actually use it ? I'm using AHFormatter to transform my stylesheets and I have to add an external function written in a different language than xslt, preferably C++ or C#. Is that possible ? I mean I don't really understand the way that it works. Actually will it work just fine if I use a java code inside the <script> tags ? I don't understand how the code is interpreted or something like that. Can anyone lighten it up a but for me ? In the specification it's stated that my processor must support the language of the script. In AHFormatter the msxml is integrated and I'm not supposed to use any other. What languages are supported by him ? I looked through the internet and found some microsoft references(http://msdn.microsoft.com/en-us/library/533texsx(vs.71).aspx) but the problem is that I don't want to process the xml outside AHFormatter and If I understood that microsoft article clearly they tell me to write a program in C# that will do the transformation outside. It's not my goal 'cause I need something to be done in one step just using my formatter. thanks in advance for any tips.

Link to post
Share on other sites

Well the document you cite is a working draft that was abandoned in 2001 so don't expect your favourite XSLT processor in 2011 to support features outlined there. The current version of XSLT is XSLT 2.0, instead of allowing you to write functions in scripting languages it allows you to write functions in XSLT itself. XSLT 2.0 processors are Saxon 9, AltovaXML, XQSharp and Intel and IBM also offer one as part of their application server products like WebSphere.As for MSXML, it supports a proprietary ms: script extension element that allows you to implement functions in JScript or VBScript so if your tool uses MSXML you might be able to use that approach. http://msdn.microsoft.com/en-us/library/ms256042.aspx has an example with sample code using JScript that should work with MSXML (as long as you ignore other parts of the documents like an assembly element that are specific to .NET).

Link to post
Share on other sites

Yes, the official names are JScript and VBScript, as documented on http://msdn.microsoft.com/en-us/library/d1et7k7c%28v=VS.85%29.aspx, that is what is available with MSXML and its proprietary ms: script element. If you want to pass in nodes to script or pass back nodes from script to XSLT you need to make yourself familiar with the MSXML object model http://msdn.microsoft.com/en-us/library/ms763742%28v=VS.85%29.aspx. And if you want to use script with MSXML 6 you need to be aware that MSXML 6 by default has tighter security settings than earlier versions http://msdn.microsoft.com/en-us/library/ms754621%28v=VS.85%29.aspx, so script in XSLT is disabled by default.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...