You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Marius Scurtescu <ma...@multiactive.com> on 2000/11/02 01:37:05 UTC

param tag and other suggestions

Hi,

I run into a problem with the 'apply' tag: there is no way
specify a stylesheet parameter.

By looking at the source code I realized that it would be 
quite easy to add this functionality, and since I needed
it I decided to implement it.

The way I solved the problem is by adding an extra tag,
called 'param', which is supposed to be used only directly
inside an 'apply' tag. This 'param' tag will get the stylesheet
parameter name and value and pass them to the 'apply' tag.
The 'apply' tag will set these parameters, if any, to the
XSLT processor just before doing the processing.

An example:
<xsl:apply xml="some.xml" xsl="some.xsl">
  <xsl:param name="name1" value="value1"/>
  <xsl:param name="name2" param="reqname"/>
</xsl:apply>

The parameter value can be specified in two ways: directly
with the 'value' attribute or by referencing a request
parameter with the 'param' attribute.

I added tow classes to the package: ParamTag and ParamTEI.
ApplyTag was slightly modified. It has a method, setParam,
through which one can add parameters and these parameters
are applied before processing. I added a comment starting
with "// marius:" where I modified ApplyTag.

Is there a process in place through which I could get
commit rights?

The attached zip files contains the added and modified
source code and tld and also the compiled code if you
want to try this out.

A few other suggestions and comments:

- the "xml" attribute of the apply tag is not very useful,
it will try to locate an xml file in the folder where the
application is installed but any realistic xml file will not
reside there

- the body of the 'apply' tag can contain the actual xml file
and this does not make much sense; the xml part of the
transformation is the most likely to be the dynamic one and
you would not hard code it into your jsp file; it would make
all the sense in the world to hardcode the xsl file since
this represent style just as jsp does

- I suggest adding two new tags: xml and xsl; these tags
would be used inside the apply tag and will offer an
alternative to hardcode the xml and xsl content

An example using the xsl:
<xsl:apply xml="some.xml">
  <xsl:param name="name" value="xxx"/>
  <xsl:xsl>
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="...">
      <xsl:output method="html" indent="yes"/>
      ...
    </xsl:stylesheet>
  </xsl:xsl>
</xsl:apply>

If these tags are used then the body of 'apply' can be always
ignored and the xml and xsl data would be set by these
inner tags.

It would also make sense to create an ApplyTEI class to deal 
with the arguments instead of doing this in the ApplyTag itself.

I apologies if some of my observations are stupid due
to ignorance, I am new to this list and to xsl.

Regards,
Marius

-- 
------------------
Marius Scurtescu, Software Engineer
Tel: (604) 899-2835 Fax: (604) 899-2899
mailto:marius@multiactive.com
Multiactive Software Inc. http://www.multiactive.com
------------------
Attract and retain customers with Multiactive Software --
proud winners of PC WEEK's "Best of COMDEX" award.
------------------

Re: param tag and other suggestions

Posted by Boyd Waters <bw...@aoc.nrao.edu>.
Marius:

I found your email regarding the XSL tag quite useful. Thanks for
attaching the code to your email.

> - the "xml" attribute of the apply tag is not very useful,
> it will try to locate an xml file in the folder where the
> application is installed but any realistic xml file will not
> reside there
> [snip]

I made a simple change to the xsl include taglib so that the "page"
parameter is a full URL. This makes the usage of the include tag
slightly more complex, since you have to explicitly supply an absolute
URL, but makes the tag much more useful, I think.

As an example:

<xsl:apply xsl="/xsl/recent-links.xsl">
 <xsl:apply xsl="/xsl/rdf-to-dl.xsl">
  <xsl:apply xsl="/xsl/rss09-to-10.xsl">
    <xsl:include page="http://www.foobar.com/slashdot.rdf"/>
  </xsl:apply>
 </xsl:apply>
</xsl:apply>

This code snippet retrieves the /. RSS file, converts it to the
(proposed) RSS 1.0 format, and then creates a formatted HTML definition
list based on this RDF.

Note that the body of the apply tag can indeed contain "dynamic"
content.

You can get the XSL stylesheets for this example here:

http://www.aoc.nrao.edu/~bwaters/pub/xsl

Thanks to Eric @ 4xt.org for the RSS processing. Check out
http://4xt.org

You can get the modified xsl:include taglib source here:

http://www.aoc.nrao.edu/~bwaters/pub/IncludeTag.java

Hope this helps,
-- boyd

PS:
[shameless plug]
I'll have much more to say about RSS and XSLT processing with my
ArticleMan documentation, which is publically available as a static
mirror to my development web server at 

http://www.aoc.nrao.edu/~bwaters/

Stay Tuned!

---------
Boyd Waters                                          bwaters@nrao.edu
National Radio Astronomy Observatory              http://www.nrao.edu
PO Box 0 Socorro, NM 87801                               505.835.7346

                                        http://www.zocalo.net/~waters
                                                    waters@zocalo.net
---------

Re: param tag and other suggestions

Posted by Marius Scurtescu <ma...@multiactive.com>.
I was thinking that it should not try to guess where the file
is and allow for an absolute path to be specified. This path
can either be hardcoded into the jsp page, dynamically
created by a bean or passed as a init parameter to the jsp page.

"David M. Karr" wrote:
> 
> >>>>> "Marius" == Marius Scurtescu <ma...@multiactive.com> writes:
>   Marius> A few other suggestions and comments:
> 
>   Marius> - the "xml" attribute of the apply tag is not very useful,
>   Marius> it will try to locate an xml file in the folder where the
>   Marius> application is installed but any realistic xml file will not
>   Marius> reside there
> 
> Obviously, a more reasonable strategy is to look for it on the
> CLASSPATH.  I would think this should be the default, but in order to
> make this happen, you have to build a subclass of EntityResolver
> (perhaps called "ClassPathEntityResolver") which looks for it on the
> CLASSPATH.  I've done this for XML parsing code that wasn't related to
> XSLT transformations, but I would think a similar function should be
> available from the XSLT parser.
> 
> --
> ===============================================================================
> David M. Karr     ; dkarr@tcsi.com  ; w:(425)487-8312 ; TCSI & Best Consulting
> Software Engineer ; Unix/Java/C++/X ; BrainBench CJ12P (#12004)

-- 
------------------
Marius Scurtescu, Software Engineer
Tel: (604) 899-2835 Fax: (604) 899-2899
mailto:marius@multiactive.com
Multiactive Software Inc. http://www.multiactive.com
------------------
Attract and retain customers with Multiactive Software --
proud winners of PC WEEK's "Best of COMDEX" award.
------------------

Re: param tag and other suggestions

Posted by "David M. Karr" <dk...@tcsi.com>.
>>>>> "Marius" == Marius Scurtescu <ma...@multiactive.com> writes:
  Marius> A few other suggestions and comments:

  Marius> - the "xml" attribute of the apply tag is not very useful,
  Marius> it will try to locate an xml file in the folder where the
  Marius> application is installed but any realistic xml file will not
  Marius> reside there

Obviously, a more reasonable strategy is to look for it on the
CLASSPATH.  I would think this should be the default, but in order to
make this happen, you have to build a subclass of EntityResolver
(perhaps called "ClassPathEntityResolver") which looks for it on the
CLASSPATH.  I've done this for XML parsing code that wasn't related to
XSLT transformations, but I would think a similar function should be
available from the XSLT parser.

-- 
===============================================================================
David M. Karr     ; dkarr@tcsi.com  ; w:(425)487-8312 ; TCSI & Best Consulting
Software Engineer ; Unix/Java/C++/X ; BrainBench CJ12P (#12004)