Hi Michael,
thanks a lot four your feedback.
Earlier today I used Saxon 8.4, but updated now to 8.7. The problem
might have been an earlier bug or a reload issue on my side.
The code you have seen is just some ugly test code without any real use
(yet).
I would really like to use XSL for this function, but it includes tons
of ifthenelse and sequences that have to be run through and checked.
And this would look horrible in XSL. There would be tons of lines of
code and it would be unmaintainable. So I think that the only solution
is a small java extension that will handle these checks (that are
described on two sheets of paper).
Cheers,
Mathias
Am Donnerstag, den 23.03.2006, 13:12 +0000 schrieb Michael Kay:
> Firstly, I've no idea why you're doing this: why use a Java extension to =
do
> something that can be done much more straightforwardly in XSLT?
>=20
> Secondly, I can't reproduce the problem. Running your code as written, I =
get
> a NullPointerException because getNamedItem("@position") returns null; if=
I
> correct that to getNamedItem("position") I get the output
> net.sf.saxon.dom.AttrOverNodeInfo@... I don't think DOM defines what
> toString() should do, but the Saxon implementation is just using the defa=
ult
> Object.toString(). The obvious way to get the string value of the attribu=
te
> is:
>=20
> pos =3D ((Element)position).getAttribute("position");
>=20
> and this works just fine.
>=20
> My advice would be:
>=20
> (a) do this in XSLT, not in Java
>=20
> (b) if you really can't do it in XSLT, use the Saxon NodeInfo interface
> rather than DOM interfaces
>=20
> This doesn't explain the ClassCastException. To discover what caused that=
,
> we'll need to find out what's different in your environment from mine. St=
art
> by supplying a full stylesheet, full source document, details of what
> version of Saxon and Java you are using, describing how you invoked the
> transformation and what is on your classpath. Running with the TJ option
> might also be helpful  it should cause a stacktrace of the exception.
>=20
> Michael Kay
> http://www.saxonica.com/
>=20
> > Original Message
> > From: saxonhelpadmin@...=20
> > [mailto:saxonhelpadmin@...] On Behalf Of=20
> > Mathias Payer
> > Sent: 23 March 2006 12:30
> > To: saxonhelp@...
> > Subject: [saxon] Problem with XSLJava extension
> >=20
> > Hi list,
> >=20
> > I've got a problem using the xsl to java extension.
> >=20
> > I want to pass a node to a Java function and then walk to the root,
> > checking the attribute @position for every element.
> >=20
> > I use the following XSL call:
> > 
> > <xsl:variable name=3D"aenderung_xpath">
> > <xsl:valueof select=3D"gmglgblpos:resolveXPath(.)"=20
> > =20
> > xmlns:gmglgblpos=3D"java:biz.gmg.GMGBuch.LGBl.PositionResolver"/>
> > </xsl:variable>
> > 
> >=20
> > And have the following Java code:
> > 
> > package biz.gmg.GMGBuch.LGBl;
> >=20
> > import org.w3c.dom.Node;
> >=20
> > public class PositionResolver {
> > public static String resolveXPath(Node position) {
> > String pos =3D null;
> > if (position.hasAttributes() &&=20
> > position.getAttributes().getNamedItem("position")!=3Dnull) {
> > =09
> > System.err.println("foo"+position.getAttributes().getNamedItem
> > ("position"));
> > pos =3D=20
> > position.getAttributes().getNamedItem("@position").toString();
> > } else
> > pos =3D "x";
> > return pos;
> > }
> > }
> > 
> >=20
> > And I get the following exception:
> > Error on line 39 of=20
> > file:XSLInput/LGBl/transformations/LGBl_Apply_Aenderungen_LGBl.xsl:
> > Error in call to extension function {public static java.lang.String
> > =20
> > biz.gmg.GMGBuch.LGBl.PositionResolver.resolveXPath(org.w3c.dom
> > .Node)}: Exception in
> > extension function java.lang.ClassCastException:=20
> > net.sf.saxon.tinytree.TinyAttributeImpl
> > Error starting transformation=20
> > (file:XSLInput/LGBl/transformations/LGBl_Apply_Aenderungen_LGBl.xsl)
> > ; SystemID:=20
> > file:XSLInput/LGBl/transformations/LGBl_Apply_Aenderungen_LGBl
> > .xsl; Line#: 39; Column#: 1
> > net.sf.saxon.trans.DynamicError: Error in call to extension=20
> > function {public static java.lang.String=20
> > biz.gmg.GMGBuch.LGBl.PositionResolver.resolveXPath(org.w3c.dom
> > .Node)}: Exception in extension function=20
> > java.lang.ClassCastException: net.sf.saxon.tinytree.TinyAttributeImpl
> >=20
> > The exception happens in line 9 which is the !=3Dnull check.
> >=20
> > Could this be a saxon bug or am I doing something terrible wrong?=20
> > Is there a better way to pass this node to my java function?
> > (I thought about JDom, but this did not work either)
> >=20
> > Cheers,
> > Mathias
> >=20
> > =20
> > Information about me, my projects and contact details:
> > http://nebelwelt.net
> >=20
>=20
>=20
>=20
>=20
> 
> This SF.Net email is sponsored by xPML, a groundbreaking scripting langua=
ge
> that extends applications into web and mobile media. Attend the live webc=
ast
> and join the prime developer group breaking into this new coding territor=
y!
> http://sel.asus.falkag.net/sel?cmd=3Dlnk&kid=3D110944&bid=3D241720&dat=
=3D121642
> _______________________________________________
> saxonhelp mailing list
> saxonhelp@...
> https://lists.sourceforge.net/lists/listinfo/saxonhelp
=20
Information about me, my projects and contact details:
http://nebelwelt.net
