Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling function define in a script embeded in xslt from another xslt file

 
Patrick Nadau
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help please.
I have javacript defined in an xslt file called file_a.xsl.
I have also a second xslt file called file_b.xslt. I pass the two xsl files as a parameter to an html file(called Ajax_display.html)which is to call the XSLT for some XSLT processing. Unfortunately I get an error which states that the xsl data is not read correctly.

Her is the html file Ajax_display.html:


------------------

Her is file_a.xsl:



Her is file_b.xsl:



I have been struggling to call the sayHello() function defined in file_a.xsl from file_b.xsl.

I will be happy for a help in solving this problem




 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual way to use a template from one XSLT document in another XSLT document is via the <xsl:include> or <xsl:import> elements.

Edit: um... I see you already did that:

But not surprisingly, this won't include anything from file_a.xsl. You used the wrong file name.
 
Patrick Nadau
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help. I have corrected the file name by using file_a.xsl as the included file instead of helloXSL.xsl.
I later found out that the Ajax_display.html cannot run in the browser when I embed some ajax code in file_b.xsl.

The javascript function is call when I try to run the code without an XSL processor.
I will therefore like to know if it is possible to embed javascript in xsl file and then run this using an XSLT processor.
If this can be done, I will be happy for some hints about how that can be done
 
g tsuji
Ranch Hand
Posts: 672
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your overall layout of xsl documents and functionality as such use msxsl extension function. It will be operative in msxml2 technology. It won't be working if you now happen to execute the transformation in application written in java, rather than as asp application, using probably, but not necessary, xalan xslt processor. You cannot change a bit this or a bit that to make it work. You can look into xalan extension function for the same functionality. If it is only "hello xsl" type of call, it should not be that complicated.
[1] Write a public class (X, say) with a static member (say sayHello()) that return string "hello xsl".
[2] Bind an extension namespace "http://xml.apache.org/xslt/java" with prefix (arbitrary, say, java) in the xslt document (your file_b.xsl) in the root element xsl:stylesheet.
[3] Instead of foo:sayHello(), you put java:X.sayHello() instead.
[4] If there involve some package as well, the path pointing to the class X should be adjusted.
That is about it.

This page, even written years ago, would still put you in the right direction, no doubt.
http://www.ibiblio.org/xml/books/xmljava/chapters/ch17s03.html

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic