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 November 5th, 2012, 01:07 PM
Authorized User
 
Join Date: Sep 2012
Posts: 35
Thanks: 18
Thanked 0 Times in 0 Posts
Exclamation Using Saxon Extensions from Java Applet

Hi.

I have a Java applet that populates an object with data extracted from the Applet's UI after it is entered by the User. Now using Saxon extensions I now want to pass this 'live' object to a transformer so it can use the data to generate XML. But how do I do this? i.e. set up the parser | transformer etc from Java.

I have created the transformer using oxygen XML and I can get it to work by setting the extensions to the applicable Jar file but how is the same done in plain old Java?

--
William
 
Old November 5th, 2012, 02:30 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The options for invoking Saxon from a Java application are explained here:

http://www.saxonica.com/documentatio...-xsl/embedding

and further elaborated in the Javadoc.
__________________
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 (November 6th, 2012)
 
Old November 9th, 2012, 10:36 AM
Authorized User
 
Join Date: Sep 2012
Posts: 35
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Hello. Having finally had time to get back to this and read the documentation I am still no further forward, as I still see no way of "registering" my POJO class or providing an instance of it so I can access it within my Style Sheet.

There are methods to registerExtensionFunction available on the Processor in the s9api, but my object isn't derived from the expected type.

I know what I want to do can be done as I have a version using a different Class albeit within the Oxygen IDE, but how to actually :
Code:
processor = new Processor(false) ;
**************
processor.setExtension(my.extension.class) ;
processor.setExtensionInstance(myInstance) ;
**************
compiler = processor.newXsltCompiler() ;
executable = compiler.compile(style) ;
source = processor.newDocumentBuilder().build(streamSource) ;
output = processor.newSerializer(new File(f.toString())) ;
transformer = executable.load() ;
transformer.setInitialContextNode(source) ;
transformer.setInitialTemplate(new QName("build")) ;
transformer.setDestination(output) ;
transformer.transform() ;
So in the XSLT I can use this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:RM="java:you.RM.Definition" exclude-result-prefixes="xs RM">
    <xsl:output method="xml" indent="yes" encoding="UTF-8" version="1.0"/>
    <xsl:template name="build">
        <xsl:variable name="Def" select="RM" />
        <xsl:element name="definition">
            <xsl:attribute name="title" select="RM:getTitle($Def)"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>
This is driving me to distraction so I'd really appreciate some help here.

--
William
 
Old November 9th, 2012, 11:32 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't know where you are going wrong, because you haven't given any clues about what you are doing. So it's hard to do anything other than point you to the documentation; but I've already done that.

The first thing to be clear on (well, if you've read the documentation you already know this) is that there are two kinds of extension function mechanism, called "reflexive" extension functions and "integrated extension functions" and they are not all available in all product releases.

But if you can give a clear description of what you are doing and how it is failing, then it will be much easier to help you. And it would be better to do it on the Saxon forum at http://saxonica.plan.io.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Java saxon JohnBampton XSLT 2 February 17th, 2010 06:21 AM
Extensions in Java and null pointers rushman XSLT 3 November 3rd, 2009 12:44 PM
Jumping into java extensions to Saxon mphare XSLT 2 April 29th, 2008 10:02 PM
entity handling with java extensions stolte XSLT 2 January 23rd, 2008 05:31 AM
Saxon java question amhicraig XSLT 1 December 7th, 2007 01:21 PM





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