Re: xalan-j extension passing the value of a xsl:variable to the extension class

Nathan Nadeau <[email protected]> Mon, 04 Oct 2010 08:53:56 -0400
Newsgroups gmane.text.xml.xalan.java.user
Organization Gleim Publications
Message-ID <[email protected]>
Markus,

The expression "exslt:node-set($def)/bo/totals" is not getting evaluated 
because you list it in a non-xsl (<xsl:>) element. Because 
<my:lineWeight> is not using the XSL namespace, the XSLT processor 
thinks it is just an element that is to be copied to the output. 
Therefore the value of your select attribute is just the string 
"exslt:node-set($def)/bo/totals", and that is what your extension 
function is receiving.

Try using

<my:lineWeight select="{exslt:node-set($def)/bo/totals}" />

in your XSLT code, which will tell the processor to evaluate the 
expression (note the curly braces).

Sticker, Markus / Kuehne + Nagel / Ham MI-EC /external wrote:
> Hello,
>
> I have a problem with my extension, because I didn't get it working to pass a 
> value of a xsl:variable to my extension.
>
> -------8<-------- XSLT-CODE ----------------------
> 		...
> 		<xsl:variable name="def">
> 	           <bo>
> 			<item>1</item>
> 			<line>4</line>
> 			<totals>6</totals>
>                 </bo>
> 		</xsl:variable>
> 		<my:lineWeight select="exslt:node-set($def)/bo/totals" />
> 		
> 		....
> 		
> 		
>
> -------8<-------- Java-CODE ----------------------
>
> 	public void line(org.apache.xalan.extensions.XSLProcessorContext context,
> 			org.w3c.dom.Element elem) {
> 		
> 		  String value = elem.getAttribute("select");
> 				    int val;
> 		    try 
> 		    {
> 		      val = Integer.parseInt (value);
> 		    } catch (NumberFormatException e) 
> 		    {
> 		        e.printStackTrace ();
> 		        val = 0;
> 		      }
> 		    
> 		lineCount += val;
> 	}
>
>
> -------8<-------- Error ----------------------
>
> java.lang.NumberFormatException: For input string: "exslt:node-set($def)/bo/totals"
> 	at java.lang.NumberFormatException.forInputString(Unknown Source)
> 	at java.lang.Integer.parseInt(Unknown Source)
> 	at java.lang.Integer.parseInt(Unknown Source)
> 	at kn.iopm.xalan.ext.textFiller.line(textFiller.java:51)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> 	at java.lang.reflect.Method.invoke(Unknown Source)
> 	at org.apache.xalan.extensions.ExtensionHandlerJavaClass.processElement(ExtensionHandlerJavaClass.java:517)
> 	at org.apache.xalan.templates.ElemExtensionCall.execute(ElemExtensionCall.java:234)
> 	at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:425)
> 	at org.apache.xalan.templates.ElemForEach.execute(ElemForEach.java:265)
> 	at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
> 	at org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:394)
> 	at org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:248)
> 	at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
> 	at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2270)
> 	at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1356)
> 	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
> 	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1273)
> 	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1251)
> 	at kn.iopm.xalan.ext.run_test.main(run_test.java:28)
>
>
>
> Does somebody know what I'm doing wrong? It seams that the SELECT-Attribute wasn't executed.
> thanks for your help
>
> best regards
>
> Markus
>
> Kuehne + Nagel (AG & Co.) KG, Geschaeftsleitung: Hans-Georg Brinkmann (Vors.), Dirk Blesius, Reiner Heiken, Bruno Mang, Alfred Manke, Christian Marnetté, Mark Reinhardt, Jens Wollesen, Klaus Jaeger (stellv.), Sitz: Bremen, Registergericht: Bremen, HRA 21928, USt-IdNr.: DE 812773878, Persoenlich haftende Gesellschaft: Kuehne & Nagel A.G., Sitz: Contern/Luxemburg Geschaeftsfuehrender Verwaltungsrat: Klaus-Michael Kuehne
>
>
>
>   

-- 
Nathan Nadeau
[email protected]
Software Development
Gleim Publications, Inc.
http://www.gleim.com