[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: accessing (xml) objects from xsl

Subject: RE: accessing (xml) objects from xsl
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 5 Jul 2002 15:45:27 +0100
pass object to xslt
> I was using Saxon 6.5.2 and could not get points 1 nor 2 
> working below.

Point 1: calling Java from Saxon. There is a detailed explanation of how
to do this at http://saxon.sourceforge.net/saxon6.5.2/extensibility.html

Point 2: passing a DOM object to XSLT. Saxon 6.5.2 essentially has two
levels of DOM support. When passing parameters, or returning nodes from
Java extension functions, Saxon only accepts DOM nodes that were
constructed using Saxon itself, not nodes constructed with an arbitrary
third-party DOM implementation. The principal source document can be an
arbitrary DOM - though this isn't really recommended, because in general
it's inefficient. If you want to pass a parameter whose value is a
reference to a set of nodes in the principal source document, then the
closest approximation in Saxon to the way yo are doing it in MSXML3 is
to pass an XPath expression as a string parameter, and evaluate this
using saxon:evaluate().

If you're coming from a Microsoft world you probably think of the DOM
and the XSLT processor as pretty closely coupled. With Saxon, they are
quite strongly separated: you can integrate them if you must, but they
aren't a good fit. It's much better to use Saxon's native tree
structures if possible, as these conform to the XPath data model rather
than the DOM data model.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx  

 I 
> tried it with Xalan-J 2 and point 2 below now seems to work.
> 
> These questions arised from the process of trying to use xsl 
> templates that 
> were created with the MSXML 3.0 XSLT processors and as such 
> we were using 
> their addObject() functionality and passing a DOM tree to be 
> used in the xsl 
> sheet the following way:
> 
> stylesheet tag:
> ====
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> xmlns:preprocessors="urn:pre-process">
> ====
> 
> a parameter using it:
> ====
> <xsl:param name="someparam" 
> select="preprocessors:get-selectNodes('PREPROCPROCESSORS/SOMEP
> ATH/FILE')" /> ====
> 
> Question is: is it possible to get this working (using custom 
> extensions?) 
> with either Saxon or Xalan-J?
> 
> Thanks!
> Sean.
> 
> 
> >From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
> >Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> >Subject: RE:  accessing (xml) objects from xsl
> >Date: Fri, 5 Jul 2002 10:38:05 +0100
> >
> >The interface between XSLT and Java depends on which XSLT 
> processor you 
> >are using. So you'll need to identify the processor before 
> anyone can 
> >answer the question.
> >
> >Michael Kay
> >Software AG
> >home: Michael.H.Kay@xxxxxxxxxxxx
> >work: Michael.Kay@xxxxxxxxxxxxxx
> >
> > > -----Original Message-----
> > > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of s s
> > > Sent: 04 July 2002 14:28
> > > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> > > Subject:  accessing (xml) objects from xsl
> > >
> > >
> > > Hello!
> > >
> > > I have looked up these two questions in the archives but 
> don't seem 
> > > to find a complete answer. If anybody could help I would be 
> > > greatful.
> > >
> > > two questions:
> > >
> > > 1) accessing java objects from xslt:
> > > I have tried using the following code to attach a java 
> object to my 
> > > xsl
> > > transformer:
> > >
> > > transformer.setParameter("blop", someObject);
> > >
> > > now I want to call the method in this function from xsl, 
> how do I do 
> > > this? i.e. I would like to call someObject.doSomething('bla') from
> > > the xsl file.
> > > Could someone help me out with an example! thanks...
> > >
> > >
> > > 2) passing a DOM object to xslt: (similar to above)
> > > I am trying to access a DOM element from xslt, but it seems to be 
> > > passed through as null object when it is not!
> > >
> > > -----java-----
> > >   javax.xml.parsers.DocumentBuilderFactory df =
> > >      javax.xml.parsers.DocumentBuilderFactory.newInstance();
> > >   javax.xml.parsers.DocumentBuilder db = df.newDocumentBuilder();
> > >   org.w3c.dom.Document doceroo = db.newDocument();
> > >   org.w3c.dom.Element nds = doceroo.createElement("nds");
> > >   doceroo.appendChild(nds);
> > >   nds.setAttribute("bla","8.5");
> > >   transformer.setParameter("blop", doceroo);
> > > -----java-----
> > >
> > > ---- xsl -----
> > > 	<?xml version="1.0"?>
> > > 	<xsl:stylesheet version="1.0" 
> > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> > > 	<xsl:param name="blop" />
> > > 	<xsl:output method="html" encoding="UTF-8"/>
> > > 	<xsl:template match="*">
> > > 		<html>
> > > 		<body>
> > >
> > > |<xsl:value-of select="$blop" />|
> > >
> > > 		</body>
> > > 		</html>
> > > 	</xsl:template>
> > > 	</xsl:stylesheet>
> > >
> > > ---- xsl -----
> > >
> > > --- result ---
> > > <?xml version="1.0" encoding="UTF-8"?>
> > >
> > > <html>
> > >
> > >   <body>
> > >
> > >       |[#document: null]|
> > >
> > >   </body>
> > >
> > > </html>
> > >
> > > --- result ---
> > >
> > > Sean.
> > >
> > >
> > > _________________________________________________________________
> > > MSN Photos is the easiest way to share and print your photos: 
> > > http://photos.msn.com/support/worldwide.aspx
> > >
> > >
> > >  XSL-List info and archive:  
> > > http://www.mulberrytech.com/xsl/xsl-list
> > >
> >
> >
> >  XSL-List info and archive:  
> http://www.mulberrytech.com/xsl/xsl-list
> 
> 
> 
> 
> 
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos: 
> http://photos.msn.com/support/worldwide.aspx
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.