You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Maurice Schoenmakers <ma...@they-do-it.com> on 2002/06/16 10:00:07 UTC

XSLT parameters that are objects and not strings

Hi cocoon users,

I would like to pass parameters to an XSLT transformer that are not strings
but objects.
(I like to use objects as non XSLT variable for Java calls in XALAN
extensions).

I used an action to create sitemap parameters and passed them to the
transformer. But it doesnt't work, as the object is transformed to a string
with toString() before the value is passed to the XSLT processor.


example:
A custom action adds a sitemap parameter  ->  ... map.put("person", new
Person() ); return map;
In the sitemap the paramter it tried to pass to the transformer:
 <map:transform src="z.xsl">
                    <map:parameter name="data" value="{person}" />
   ...

Unfortunatly {person} results in a string as it calls Person.toString(),
but I would like to pass the reference of the person in the XSL parameter
"data"

After browsing some code, it seams that this limitation is caused only by
the sitemap and not by the XSL processor ?

Has anybody an idea how to pass objects as parameters to XSLT ? ,
Should I use an other sitemap syntax for the parameter ?
Implement an own transformer :-( ??


Thank you for any comment,

Maurice





---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


RE: XSLT parameters that are objects and not strings

Posted by Luca Morandini <lu...@tin.it>.
Maurice,

I'm afraid what you're trying to do is impossible.

XSL can accept only strings and Tree fragments (something less than a
node-set, but more than a string) as <xsl:param> values.

To put it simply, Java and XSL don't mix THAT easily... though, some Xalan
(hence, proprietary) extensions might change that.

What you could do is generate an XML document (i.e. a stream of SAX eventa)
as the output of your Java program and pass it along the pipeline to the XSL
transformer for further processing.

Alternatively, you may override your Person.toString() method, in order to
generate a string representation of that instance for further parsing by the
receiving stylesheet: by means of substring-after() and substring-before()
functions in XSL a lot can be accomplished :)

Best regards,

---------------------------------------------
               Luca Morandini
               GIS Consultant
              lmorandini@ieee.org
http://utenti.tripod.it/lmorandini/index.html
---------------------------------------------


> -----Original Message-----
> From: Maurice Schoenmakers [mailto:maurice.schoenmakers@they-do-it.com]
> Sent: Sunday, June 16, 2002 10:00 AM
> To: cocoon-users@xml.apache.org
> Subject: XSLT parameters that are objects and not strings
>
>
> Hi cocoon users,
>
> I would like to pass parameters to an XSLT transformer that are
> not strings
> but objects.
> (I like to use objects as non XSLT variable for Java calls in XALAN
> extensions).
>
> I used an action to create sitemap parameters and passed them to the
> transformer. But it doesnt't work, as the object is transformed
> to a string
> with toString() before the value is passed to the XSLT processor.
>
>
> example:
> A custom action adds a sitemap parameter  ->  ... map.put("person", new
> Person() ); return map;
> In the sitemap the paramter it tried to pass to the transformer:
>  <map:transform src="z.xsl">
>                     <map:parameter name="data" value="{person}" />
>    ...
>
> Unfortunatly {person} results in a string as it calls Person.toString(),
> but I would like to pass the reference of the person in the XSL parameter
> "data"
>
> After browsing some code, it seams that this limitation is caused only by
> the sitemap and not by the XSL processor ?
>
> Has anybody an idea how to pass objects as parameters to XSLT ? ,
> Should I use an other sitemap syntax for the parameter ?
> Implement an own transformer :-( ??
>
>
> Thank you for any comment,
>
> Maurice
>
>
>
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>