script in xsl
Added by Anonymous almost 19 years ago
Legacy ID: #3528526 Legacy Poster: zon2 (zon2)
hi all, i got a problem with addressing a java file wich is invoked in my xsl. how do i address the file and method correctly? thx! my xsl: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="org.test.position.Position" extension-element-prefixes="java"> <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/> <xsl:template match="catalog"> <xsl:variable name="x" select="java:calc_x(4,5)"/> <X3D profile="Immersive" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.0.xsd" version="3.0"> <Scene> <Transform translation="1 0 0"> <Shape> <Text string="{$x}"/> </Shape> </Transform> </Scene> </X3D> </xsl:template> </xsl:stylesheet> my java file named Position.class: package org.test.position; public class Position{ public Double calc_x(int elems, int i){ Double calc_x = Math.cos((360/elemsi)(elems1.5Math.PI)/3602Math.PI); return calc_x; } } this file is in the folder /org/test/position, relativ to the xslt and xml file. when i process the xsl with saxon i get the error: Cannot find a matching 2-argument function named {org.test.position.Position}calc_x()
Replies (4)
Please register to reply
RE: script in xsl - Added by Anonymous almost 19 years ago
Legacy ID: #3528603 Legacy Poster: Michael Kay (mhkay)
Full instructions are at http://www.saxonica.com/documentation/extensibility/functions.html I would recommend making the method static, as you then don't need to create an instance of the class in order to call it. You should then be able to do <xsl:value-of select="Position:calc_x(11,12)" xmlns:Position="java:org.test.position.Position"/> You don't need to set extension-element-prefixes. If Saxon still doesn't locate the method, use the -TJ option for diagnostics. Michael Kay
RE: script in xsl - Added by Anonymous almost 19 years ago
Legacy ID: #3528831 Legacy Poster: zon2 (zon2)
thanks for your help. saxon cannot load the java file. did i save it in a wrong location? i think i invoke the function like it is described in the tutorial?! the function is static, too. my trans4.xsl in C:\ma : <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:Position="java:org.test.pos.Position"> <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/> <xsl:template match="catalog"> <xsl:variable name="x" select="Position:calc_x(4,5)"/> <X3D profile="Immersive" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.0.xsd" version="3.0"> <Scene> <Transform translation="1 0 0"> <Shape> <Text string="{$x}"/> </Shape> </Transform> </Scene> </X3D> </xsl:template> </xsl:stylesheet> my Position.class in C:\ma\org\test\pos : package org.test.pos; public class Position { public static Double calc_x(int elems, int i){ Double calc_x = Math.cos((360/elemsi)(elems1.5Math.PI)/3602Math.PI); return calc_x; } } saxon output: C:\ma>java -jar C:\saxon\saxon8.jar -TJ catalog.xml trans4.xsl >out.x3d Loading org.test.pos.Position No Java class org.test.pos.Position could be loaded Error at xsl:variable on line 8 of file:/C:/ma/trans4.xsl: XPST0003: XPath syntax error at char 20 on line 8 in {Position:calc_x(4,5)}: Cannot find a matching 2-argument function named {java:org.test.pos.Position }calc_x() Failed to compile stylesheet. 1 error detected.
RE: script in xsl - Added by Anonymous almost 19 years ago
Legacy ID: #3528916 Legacy Poster: Michael Kay (mhkay)
The class needs to be on your classpath, and you can't use the -jar option on the command line because that causes the classpath to be ignored. Use "java net.sf.saxon.Transform" instead. Michael Kay
RE: script in xsl - Added by Anonymous almost 19 years ago
Legacy ID: #3529465 Legacy Poster: zon2 (zon2)
ok, thanks! i've got it...
Please register to reply