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 December 20th, 2012, 12:52 PM
Authorized User
 
Join Date: Sep 2012
Posts: 35
Thanks: 18
Thanked 0 Times in 0 Posts
Default Java Generics and XSLT

Hello!

What I would like to do is use Generics and template my Buffer class; class Buffer <T>. This I can easily do but I then need to create instances of these buffers in my XSLTs can I do this? If so then how?

I have had a play with things but I think its 'working' by accident.

Code:
import java.util.ArrayList;

public class Template <T>
{
	ArrayList < T >values = null ;
	public Template(T value)
	{
		this.values = new ArrayList<T>() ;
	}
	
	public T getValue(int index) { return values.get(index) ; }
	public void addValue(T value) { this.values.add(value) ; }
	
	public int getSize() { return this.values.size() ; }
}
Code:
<xsl:if test="./xs:boolean(@test)">
    <xsl:variable name="tests" select="Template:new(0)"/>
    <xsl:value-of select="Template:addValue($tests, 44.3)"/>
    <xsl:value-of select="Template:addValue($tests, 'string')"/>
    <xsl:for-each select="0 to Template:getSize($tests)-1">
        <xsl:message select="'Value : ', Template:getValue($tests, .)"/>
    </xsl:for-each>
</xsl:if>
This is the output I get when executed in Oxygen.
Code:
Description: [Saxon-PE] Value : 44.3
Description: [Saxon-PE] Value : string
I would have expected an exception when assigning a string to what is (or should be) a double so am I wasting my time?

--
William
 
Old December 20th, 2012, 06:40 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Interfaces between XSLT and Java are product specific; it would really be best to ask such questions on a product-specific forum, which in this case means http://saxonica.plan.io. I might spot a Saxon question on this forum, but it could easily go unnoticed, and the same applies to a follow-up message.

Java generics are a rather half-baked facility. I'm not really expert enough to give an explanation in the correct terminology, but the way I understand it is that they give you some compile-time checking that assignments are done correctly, but no run-time checking. That means that when you do assignments from a different language using reflection, bypassing the Java compiler, generics give you no additional type safety.
__________________
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:
WilliamYou (December 21st, 2012)
 
Old December 21st, 2012, 06:19 AM
Authorized User
 
Join Date: Sep 2012
Posts: 35
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
Interfaces between XSLT and Java are product specific; it would really be best to ask such questions on a product-specific forum, which in this case means http://saxonica.plan.io. I might spot a Saxon question on this forum, but it could easily go unnoticed, and the same applies to a follow-up message.
I have submitted a support request to this site, but I posted here as I assumed that someone might know the answer as I for one do not think that I'm the first person to want to do this.

Quote:
Java generics are a rather half-baked facility. I'm not really expert enough to give an explanation in the correct terminology, but the way I understand it is that they give you some compile-time checking that assignments are done correctly, but no run-time checking.That means that when you do assignments from a different language using reflection, bypassing the Java compiler, generics give you no additional type safety.
OK. I'll wait and see what comes from the submission.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Java XSLT technologies ojasrege Java Basics 1 November 8th, 2007 01:17 AM
Using XSLT and JAVA trinkets XSLT 4 April 4th, 2007 02:13 PM
XSLT and JAVA bonekrusher XSLT 3 August 9th, 2006 07:38 PM
XSLT 2.0 Transformation and JAVA markus2000 XML 2 June 22nd, 2006 04:34 AM
XSLT with Java Hind XSLT 1 May 24th, 2006 04:18 AM





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