Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Xalan-J and calls to Java

Status
Not open for further replies.

xmtb26

Programmer
Sep 12, 2007
19
GB
Background: I am running a servlet under Tomcat. The servlet is a "wrapper" for Xalan-J that transforms a given XML/XSL combo.

I have been successful in getting super basic Java calls working in my XSLs (such as string.toUpperCase or InetAddress.getLocalName).

My current need is for the XSL to be able to know the complete URL of what called it. For example, I want something like
or that I can store into a variable.
 
>My current need is for the XSL to be able to know the complete URL of what called it.

Since no xml/java/servlet person steps in, I try to offer some elements of thought that I believe should not be too far off.

[1] To get the url that is calling, it is not an xml-related problem. Let's say request be HttpServletRequest, you can store it to string variable, say surl, like this.
[tt] surl=(String)request.getRemoteAddr();[/tt]

[2] To let the xslt document aware of it is a xml-related question.
[2.1] You first set up the xslt document with a top level parameter.
[tt] <xsl:param name="remoteaddr" />[/tt]
[2.2] Then when transformer, named transformer, is set up, you set the parameter remoteaddr to the value surl.
[tt] transformer.setParameter("remoteaddr",surl);[/tt]
 
Thank you tsuji for taking the time to respond. My Xalan wrapper servlet can accept params similar to command-line calls to Xalan. Therefore, I am passing the info in via a parameter. I may be forced to write my own class to get the info like you suggest, unless I (or Tek Tip folks) can come up with an elegant "one line solution" like I do in other cases:

How I retrieve the web server's IP and box name, e.g.,
Code:
<xsl:variable name="ip.box" select="java:java.net.InetAddress.getLocalHost()"/>
<xsl:variable name="box" select="java:getHostName($both)"/>
or like make a node UPPERCASE
Code:
select="java:toUpperCase(java:java.lang.String.new(string()))"/>
or finding the version of Xalan I'm running
Code:
<xsl:value-of select="java:org.apache.xalan.Version.getVersion()"/>
 

* BUMP *

Or, determining PI
Code:
<xsl:variable name="PI" select="4.0 * Math:atan(1.0)"/>
where Math is
Code:
xmlns:Math="xalan://java.lang.Math"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top