[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Calling java from xsl - with xml as parameter


Subject: RE: [xsl] Calling java from xsl - with xml as parameter
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 6 Dec 2007 16:37:00 -0000

Calling extension functions from XSLT depends on the XSLT processor you are
using, so we can't answer without that information.

You haven't said what the Java method signature is. It sounds to me as if
the Java method is expecting a string, and so the call is taking the string
value of the supplied node, just as it would when you call an XPath function
that expects a string. But you actually seem to want the Java method to get
the XML serialization of the node - you won't get that automatically, you
will have to call a function such as saxon:serialize() to get it.

What is your Java method actually doing?

> I thought i could solve the problem by using xsl:copy-of 
> select... , but that seems to be illegal:
> 	<xsl:value-of 
> select="transf:rtrtransform(string(<xsl:copy-of select="

Well, yes, you can't have XSLT instructions in the middle of an XPath
expression (or XML elements in the middle of an XML attribute). The fact
that you're making this mistake suggests we ought to start from first
principles and look at the problem you are trying to solve and whether your
whole approach makes sense.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: richardtrans@xxxxxx [mailto:richardtrans@xxxxxx] 
> Sent: 06 December 2007 16:20
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Calling java from xsl - with xml as parameter
> 
> Hi.
> 
> I hava a xml and a xsl which are being parsed.
> 
> In the xsl i want to call a java method with a parameter, 
> which contains the source xml. The parameter can be of any type.
> The java program returns a String.
> 
> The problem is to send the xml as parameter to the java method.
> 
> I have tried following:
> Copy / Store the xml document in the variable xmlString.
> <xsl:variable name="xmlString">
> 	<xsl:copy-of select="/*[local-name()='Invoice']" /> 
> </xsl:variable>
> 
> Send the xmlString to the java method rtrtransform, but the 
> problem is, that it only sends the values to the java method. 
> When i want to send "<abc><d>hi</d><e>there<e></abd>", i only 
> get "hithere". Tags are not send.
> <xsl:variable name="myresult">
> 	<xsl:value-of select="transf:rtrtransform(string($xmlString))"/>
> </xsl:variable>
> 
> 
> I thought i could solve the problem by using xsl:copy-of 
> select... , but that seems to be illegal:
> 	<xsl:value-of 
> select="transf:rtrtransform(string(<xsl:copy-of select="
> abc" />"/>
> or
> 	<xsl:value-of select="transf:rtrtransform(string(&lt;xsl:copy-of
> select=&#034;abc&#034; /&gt;"/>
> 
> 
> Any solutions to this?
> 
> Best regards
> Richard Trans


Current Thread
Keywords