You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by John Borchardt <jo...@megootz.com> on 2001/02/20 19:50:58 UTC

Assistance on an Extension Problem

I'm a little stuck on a project I'm working on and I'm hoping that someone
might have a suggestion.  Below is a generalization of my problem...

I've got a transformation process that transforms an XML document using
XSLT.  The XSLT doc matches tags in the XML doc, like...

<CompTag name="CompA"/>

 and processes them using a custom extension function written in Java using
XSLT, like...

<xsl:template match="CompTag">
    <xsl:value-of disable-output-escaping="yes"
select="CompExt:getCompOutput(@name)" />
</xsl:template>

The extension function itself is really a factory that takes its parameters
(name in above case), determines the named component from which output is
desired in place of the tag in the result, instantiates the component, and
returns its output.

My problem is that I need information from the transformation process at
runtime, in addition to the parameters contained in the source XML document,
to determine the appropriate output and I'm not sure how to get the
information into the instantiated output component.  Is there a clean way of
piggy-backing the information on the stylesheet or XSLProcessorContext in
such a way that I can access it from the Extension function?

Any and all ideas and assistance are greatly appreciated.

Thanks,

John





Re: Assistance on an Extension Problem

Posted by John Borchardt <jo...@megootz.com>.
Absolutely perfect!  Now I get it... you create a placeholder for the
parameter physically in the stylesheet and populate it using the
setParameter() method.  Brilliant!  I was actually pretty close to that a
headache and a half ago.  I'll give it a shot.

Thanks much for your help,

John

----- Original Message -----
From: "Gary L Peskin" <ga...@firstech.com>
To: <xa...@xml.apache.org>
Sent: Tuesday, February 20, 2001 3:34 PM
Subject: Re: Assistance on an Extension Problem


> John Borchardt wrote:
> >
> > Thanks for your prompt response!
> >
> > I think that your suggestion relates directly to my point of confusion.
I
> > just can't seem to grasp an understanding for the use of the
> > ExpressionContext and XSLProcessorContext arguments as they're described
in
> > the documentation and mailing list threads.  What are these contexts
> > intended to describe?  When are they created?  What populates the
context
> > and can I place arbitrary data into the context?  If so, from where and
how
> > do I push data into the context and from where and how can I pull it
back
> > out?
> >
> > I guess what I need to be able to do is package a bunch of application
> > specific data prior to the transformation and then attach it to the
> > transformation in such a way that the Extension function can pull it out
and
> > use it.  If the either of these contexts is the means for doing this,
great.
> > I just don't get it.  Any light that you can shed on the process for me
> > would be greatly appreciated.
> >
> > Thanks again,
> >
> > John
>
> John --
>
> These contexts are designed to represent the execution environment
> created by Xalan.  You can't push any data into them directly, at least
> not yet.  They are created by Xalan and passed to your extension
> function.  You can call methods on the object and gain access to various
> parts of your Xalan execution environment.  For example, you can call
> the getContextNode() method which returns the context node from which
> the extension function was invoked.
>
> In order to package up your application specific data the way you want,
> I'd create an object in your java code prior to the transformation.
> Pass that object into the transformer as a parameter using the
> Transformer.setParameter() method.  In your stylesheet, you can receive
> that parameter by including
>
>   <xsl:param name="mystuff" select="Passed in by processor"/>
>
> as a top-level element.  Then, you can pass $mystuff to your various
> extension functions and retrieve things from there.
>
> Does this make sense?
>
> Gary
>


Re: Assistance on an Extension Problem

Posted by Gary L Peskin <ga...@firstech.com>.
John Borchardt wrote:
> 
> Thanks for your prompt response!
> 
> I think that your suggestion relates directly to my point of confusion.  I
> just can't seem to grasp an understanding for the use of the
> ExpressionContext and XSLProcessorContext arguments as they're described in
> the documentation and mailing list threads.  What are these contexts
> intended to describe?  When are they created?  What populates the context
> and can I place arbitrary data into the context?  If so, from where and how
> do I push data into the context and from where and how can I pull it back
> out?
> 
> I guess what I need to be able to do is package a bunch of application
> specific data prior to the transformation and then attach it to the
> transformation in such a way that the Extension function can pull it out and
> use it.  If the either of these contexts is the means for doing this, great.
> I just don't get it.  Any light that you can shed on the process for me
> would be greatly appreciated.
> 
> Thanks again,
> 
> John

John --

These contexts are designed to represent the execution environment
created by Xalan.  You can't push any data into them directly, at least
not yet.  They are created by Xalan and passed to your extension
function.  You can call methods on the object and gain access to various
parts of your Xalan execution environment.  For example, you can call
the getContextNode() method which returns the context node from which
the extension function was invoked.

In order to package up your application specific data the way you want,
I'd create an object in your java code prior to the transformation. 
Pass that object into the transformer as a parameter using the
Transformer.setParameter() method.  In your stylesheet, you can receive
that parameter by including

  <xsl:param name="mystuff" select="Passed in by processor"/>

as a top-level element.  Then, you can pass $mystuff to your various
extension functions and retrieve things from there.

Does this make sense?

Gary

Re: Assistance on an Extension Problem

Posted by John Borchardt <jo...@megootz.com>.
Thanks for your prompt response!

I think that your suggestion relates directly to my point of confusion.  I
just can't seem to grasp an understanding for the use of the
ExpressionContext and XSLProcessorContext arguments as they're described in
the documentation and mailing list threads.  What are these contexts
intended to describe?  When are they created?  What populates the context
and can I place arbitrary data into the context?  If so, from where and how
do I push data into the context and from where and how can I pull it back
out?

I guess what I need to be able to do is package a bunch of application
specific data prior to the transformation and then attach it to the
transformation in such a way that the Extension function can pull it out and
use it.  If the either of these contexts is the means for doing this, great.
I just don't get it.  Any light that you can shed on the process for me
would be greatly appreciated.

Thanks again,

John

----- Original Message -----
From: "Gary L Peskin" <ga...@firstech.com>
To: <xa...@xml.apache.org>
Sent: Tuesday, February 20, 2001 1:05 PM
Subject: Re: Assistance on an Extension Problem


> John Borchardt wrote:
> >
> > I'm a little stuck on a project I'm working on and I'm hoping that
someone
> > might have a suggestion.  Below is a generalization of my problem...
> > ...
> >
> > My problem is that I need information from the transformation process at
> > runtime, in addition to the parameters contained in the source XML
document,
> > to determine the appropriate output and I'm not sure how to get the
> > information into the instantiated output component.  Is there a clean
way of
> > piggy-backing the information on the stylesheet or XSLProcessorContext
in
> > such a way that I can access it from the Extension function?
> >
> > Any and all ideas and assistance are greatly appreciated.
> >
> > Thanks,
> >
> > John
>
> John --
>
> I'm not 100% sure what you're asking but, if you are using XalanJ2,
> which I would recommend, then you can add a first parameter to your
> extension function which is of type
> org.apache.xalan.extensions.ExpressionContext.  This provides some
> methods to find out things from your environment.  You don't need to
> change your stylesheet at all.
>
> Can you have a look at this class and see if it provides the methods
> that you need or let us know what additional information you need.
>
> Thanks,
> Gary
>


Re: Assistance on an Extension Problem

Posted by Gary L Peskin <ga...@firstech.com>.
John Borchardt wrote:
> 
> I'm a little stuck on a project I'm working on and I'm hoping that someone
> might have a suggestion.  Below is a generalization of my problem...
> ... 
> 
> My problem is that I need information from the transformation process at
> runtime, in addition to the parameters contained in the source XML document,
> to determine the appropriate output and I'm not sure how to get the
> information into the instantiated output component.  Is there a clean way of
> piggy-backing the information on the stylesheet or XSLProcessorContext in
> such a way that I can access it from the Extension function?
> 
> Any and all ideas and assistance are greatly appreciated.
> 
> Thanks,
> 
> John

John --

I'm not 100% sure what you're asking but, if you are using XalanJ2,
which I would recommend, then you can add a first parameter to your
extension function which is of type
org.apache.xalan.extensions.ExpressionContext.  This provides some
methods to find out things from your environment.  You don't need to
change your stylesheet at all.

Can you have a look at this class and see if it provides the methods
that you need or let us know what additional information you need.

Thanks,
Gary