Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2012, 05:49 AM
Authorized User
 
Join Date: Mar 2012
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
Default How to use method returned values in <xsl:if> condition

Hi,
I would like to use a java method's return values as operand in a <xsl:if> condition. What is the syntax for it?

When I use this
<xsl:if test="{$java:name($veh)} ='project'"> or
<xsl:if test="{java:name($veh)} ='project'"> I get exceptions.

Is there any way to avoid using temporary variable to store method returned value?
 
Old March 21st, 2012, 06:06 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The syntax for calling out to Java depends on which XSLT processor you are using.

However, the test attribute of xsl:if should never include curly braces: it's an XPath expression, not an attribute value template. So it will be something like

Code:
<xsl:if test="java:method(a,b,c) = 'xyz'">
  ...
</xsl:if>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
aravindram87 (March 21st, 2012)
 
Old March 21st, 2012, 06:39 AM
Authorized User
 
Join Date: Mar 2012
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Thanks Michael,

Worked like a charm. I used the curly brackets because I read in the book that there is a restriction in XML that we cannot have an angle bracketed markup code in an attribute. But didn't know that I can call the method directly.





Similar Threads
Thread Thread Starter Forum Replies Last Post
<xsl:when> condition failing scubin XSLT 1 May 3rd, 2010 06:42 PM
Performance for <xsl:import> and <xsl:include> vikkiefd XSLT 2 April 16th, 2008 08:06 AM
Usage of '*' in test condition of <xsl:when> vikkiefd XSLT 5 March 12th, 2008 10:31 PM
<xsl:output method=”xhtml”> crashes Tomcat li72 XSLT 1 August 13th, 2007 07:30 AM
<xsl:output method=”xhtml”> problem li72 XSLT 5 May 16th, 2007 10:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.