cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christopher Painter-Wakefield" <paint...@mc.duke.edu>
Subject RE: XSP: How to use one custom taglib from within another
Date Mon, 25 Jun 2001 19:57:40 GMT

William,

you don't appear to be using the <?xml-logicsheet href="..."?> processing
instruction to apply either of your logicsheets.  Do you have them defined
in your cocoon.properties?  I use multiple custom taglibs under C1.8.2
without any difficulty, using the <?xml-logicsheet?> processing instruction
to apply the taglibs.  You must either use the <?xml-logicsheet?> PI or
declare your namespace in cocoon.properties.  If you use the
cocoon.properties approach, you have to restart Cocoon (and you must also
restart Cocoon after modifying the taglib logicsheets).

-Christopher




Please respond to cocoon-users@xml.apache.org

To:   "'cocoon-users@xml.apache.org'" <cocoon-users@xml.apache.org>
cc:

Subject:  RE: XSP: How to use one custom taglib from within another


> This is a wild guess, but do you use <xsl:value-of ...> in the
> template of the <mylib:mytag>?

No. It just contains some logic.

Here's my setup:

Cocoon 1.8.2
Weblogic 5.1.0
Solaris 2.6
JDK 1.3

and here's the files (names changed to protect the innocent):

index.xml
------------------
<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="index.xsl" type="text/xsl"?>
<!DOCTYPE xsp:page SYSTEM "xsp-page.dtd">

<xsp:page language="java"
xmlns:myutil="http://my.company.com/XSPTagLib/MyUtil"
xmlns:xsp="http://www.apache.org/1999/XSP/Core"
xmlns:util="http://www.apache.org/1999/XSP/Util"
xmlns:legacy="http://my.company.com/XSPTagLib/Legacy"
>
     <page>
          <title>Search</title>
          <legacy:get-results c="emp"/>
     </page>
</xsp:page>


Legacy taglib (legacy.xsl)
-----------------------------------
<?xml version="1.0"?>

<xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xsp="http://www.apache.org/1999/XSP/Core"
     xmlns:util="http://www.apache.org/1999/XSP/Util"
     xmlns:legacy="http://my.company.com/XSPTagLib/Legacy"
     xmlns:myutil="http://my.company.com/XSPTagLib/MyUtil"
     version="1.0"
>

<xsl:template match="xsp:page">
     <xsp:page>
          <xsl:apply-templates select="@*"/>

          <xsp:structure>

<xsp:include>my.taglib.utils.XSPLegacyLibrary</xsp:include>
          </xsp:structure>

          <xsl:apply-templates/>
     </xsp:page>
</xsl:template>

<xsl:template match="legacy:get-legacy-data" name="get-legacy-data">
     <xsl:param name="c"><xsl:value-of select="@c"/></xsl:param>
     <xsl:param name="t"><xsl:value-of select="@t"/></xsl:param>
     <xsl:param name="q"><xsl:value-of select="@q"/></xsl:param>
     <xsl:param name="search-parameters"><xsl:value-of
select="legacy:search-parameters"/></xsl:param>

     <myutil:process-params/>
     <xsp:logic>
          String qp = null;
          Enumeration keys = queryParams.keys();
          if ( ( keys != null ) &amp;&amp; ( keys.hasMoreElements() )
) {
               while ( keys.hasMoreElements() ) {
                    String k = (String) keys.nextElement();
                    Vector v = (Vector) queryParams.get( k );
                    for(int i = 0; i &lt; v.size(); i++) {
                         qp += "&amp;" + k + "=" + v.get(i);
                    }
               }
          }
     </xsp:logic>
     <xsl:variable name="query-string">
          <xsl:choose>
               <xsl:when test="$search-parameters != ''">
                    <xsl:for-each
select="$search-parameters/legacy:search-parameter">&amp;<xsl:value-of
select="@name"/>=<xsl:value-of select="@value"/></xsl:for-each>
               </xsl:when>
               <xsl:otherwise>
                    <xsl:value-of select="$q"/>
               </xsl:otherwise>
          </xsl:choose>
          <xsp:expr>qp</xsp:expr>
     </xsl:variable>

     <util:include-expr><util:expr>
     XSPLegacyLibrary.getLegacyData(
                         "<xsl:value-of select="$c"/>",
                         "<xsl:value-of
select="$query-string"/>",
                         '<xsl:value-of select="$t"/>',
     )
     </util:expr></util:include-expr>
</xsl:template>

<xsl:template match="@*|*|text()|processing-instruction()">
     <xsl:copy>
          <xsl:apply-templates
select="@*|*|text()|processing-instruction()"/>
     </xsl:copy>
</xsl:template>

</xsl:stylesheet>

My Utility Taglib (myutil.xsl)
---------------------------------
<?xml version="1.0"?>

<xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xsp="http://www.apache.org/1999/XSP/Core"
     xmlns:myutil="http://my.company.com/XSPTagLib/MyUtil"
     xmlns:legacy="http://my.company.com/XSPTagLib/Legacy"
     xmlns:util="http://www.apache.org/1999/XSP/Util"
     version="1.0"
>

<xsl:template match="xsp:page">
     <xsp:page>
          <xsl:apply-templates select="@*"/>

          <xsp:logic>
               Hashtable queryParams = new Hashtable();
          </xsp:logic>

          <xsl:apply-templates/>
     </xsp:page>
</xsl:template>

<xsl:template match="myutil:process-params">
     <xsp:logic>
          queryParams.clear();
          Enumeration e = request.getParameterNames();
          if ((e != null) &amp;&amp; (e.hasMoreElements())) {
               while (e.hasMoreElements()) {
                    String k = (String) e.nextElement();
                    String vals[] =
request.getParameterValues(k);
                    Vector v = new Vector( Arrays.asList( vals )
);
                    queryParams.put( k, v );
               }
          }
  </xsp:logic>
</xsl:template>

<xsl:template match="@*|*|text()|processing-instruction()">
     <xsl:copy>
          <xsl:apply-templates
select="@*|*|text()|processing-instruction()"/>
     </xsl:copy>
</xsl:template>

</xsl:stylesheet>

>From the generated Java code (_index.xml)
--------------------------------------------

    xspParentNode = xspCurrentNode;
    xspNodeStack.push(xspParentNode);
    xspCurrentNode = document.createElement("myutil:process-params"); //
NOT
PROCESSING THIS TAG!
    xspParentNode.appendChild(xspCurrentNode);



    ((Element) xspCurrentNode).normalize();
    xspCurrentNode = (Node) xspNodeStack.pop();

          String qp = null;
          Enumeration keys = queryParams.keys();
          if ( ( keys != null ) && ( keys.hasMoreElements() ) ) {
               while ( keys.hasMoreElements() ) {
                    String k = (String) keys.nextElement();
                    Vector v = (Vector) queryParams.get( k );
          for(int i = 0; i < v.size(); i++) {
                         qp += "&" + k + "=" + v.get(i);
                    }
               }
          }

        xspCurrentNode.appendChild(
          xspExpr(
      this.xspParser.parse(
        new InputSource(
          new StringReader(
         String.valueOf(
     XSPLegacyLibrary.getLegacyData(
                         "emp",
                         "qp",
                         '3',
     )
     )
          )
        )
      ).getDocumentElement()
    , document)
        );

So, as you can clearly see :) , the <util:include-expr> and <util:expr> are
being processed, but <myutil:process-params/> is not.  Is the order of the
namespace declarations significant?

Thanks,


William Bagby.

-----Original Message-----
From: Christian Haul [mailto:haul@dvs1.informatik.tu-darmstadt.de]
Sent: Thursday, June 21, 2001 12:16 PM
To: cocoon-users@xml.apache.org
Cc: williamb@adone.com
Subject: Re: XSP: How to use one custom taglib from within another


On 20.Jun.2001 -- 12:11 PM, William Bagby wrote:
> I am having trouble using one of my custom tag libraries from within
> another.  I wrote a "utility" taglib which consists of some
generic methods
> and such, and I am trying to use one of the tags like this:
>
> <xsl:template match="mylib:mytag">
>    ...
>    <myUtilLib:process-request/>
>    ...
>
> </xsl:template>
>
> Yet in my generated code, the tag is being inserted as a
plain old element
> node, and no processing is being done with it.  Additionally,
I am also
> using Cocoon's built-in <util> taglib, and it's being
processed just fine.
> I know *something* is being done with my Utility library
because the code
> inside the <xsl:template match="xsp:page"> logic portion is
being inserted
> as expected.
>
> I have tried various things, such as putting it inside/outside the
> <xsp:logic> tag, and declaring the namespace in my other
taglib, but it
> still won't work. I've looked in the mailing list archive,
and on the FAQ,
> but the information on mulitple XSP taglibs is sketchy, and I've seen
> conflicting information.  Some say the "order of the
namespace declarations
> is important", some say otherwise.  And what about this enigmatic
> <?xsp-logicsheet?> PI?
>
> Any suggestions?

This is a wild guess, but do you use <xsl:value-of ...> in the
template of the <mylib:mytag>? If so, try to change it to <xsl:copy-of
...>.

Why? value-of inserts one text node while copy-of inserts a tree.

If this doesn't help, provide us with more info (which version of
cocoon, your taglibs, your cocoon.xconf)

     Chris.

--
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08





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

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


Mime
View raw message