*
The moose likes XML and Related Technologies and the fly likes calling function define in a script embeded in xslt from another xslt file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "calling function define in a script embeded in xslt from another xslt file" Watch "calling function define in a script embeded in xslt from another xslt file" New topic
Author

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

Patrick Nadau
Greenhorn

Joined: Jun 13, 2011
Posts: 2
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jun 13, 2011
Posts: 2
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

Joined: Jan 18, 2011
Posts: 499
    
    3
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

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: calling function define in a script embeded in xslt from another xslt file
 
Similar Threads
XSL
XSLT Calculations
xsl:include replaces previous defined xsl:template?
In XSLT , is reference to root node required to access child node of root node ?
XSLTProcessor problem for mozilla