cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Saravanan Bellan <sa...@siteROCK.com>
Subject RE: variables in util:include-uri
Date Sat, 19 Aug 2000 04:48:08 GMT
Thanks so much. It really helps.

-----Original Message-----
From: Ricardo Rocha [mailto:ricardo@apache.org]
Sent: Friday, August 18, 2000 8:37 PM
To: cocoon-users@xml.apache.org
Subject: Re: variables in util:include-uri


Saravanan Bellan wrote:
> 
> How can I use a variable in the href attribute of util:inlcude-uri?

Parameter values are passed to dynamic tags by means of
constant attributes or nested elements.

For example, the utility tag <util:include-uri> is used to
include XML content from any arbitrary URI:

  <p>The following is included XML content:</p>
  <util:include href="http://localhost/something.xml"/>

In this case, the URI is known at design time an is expressed
as an attribute in tag <util:include>.

When the URI is known only at request time, the URI
parameter is passed as a nested <util:href> element.
Thus:

  <p>The following is included XML content:</p>
  <util:include-uri>
    <util:href><request:get-parameter name="whereTo"/></util:href>
  </util:include-uri>

will include the contents of the URL pointed to by the
value of the HTTP request parameter "whereTo". This allows
for requests such as:

  http://localhost/dispatcher.xml?whereTo=/real/page.xml

Note that the following also works fine:

  <util:include-uri>
    <util:href>http://localhost/something.xml</util:href>
  </util:include-uri>

that is: the nested element form can also be used for
constant values if preferred.

Note: constant values used inside <util:href> are treated
by XSP as XML text() nodes. They're _not_ [Java] expressions.

Passing parameters to taglib dynamic tags as either attributes
or nested elements is an XML pattern used consistently in all
Cocoon-supplied taglibs, not only in the "util.xsl" taglib.

The criteria used is rather simplistic but uniform:

- For constant values use attributes if it makes the
  XML document more readable:

  <p>It's now <util:time format="hh:mm:ss"/></p>

- For variable values, always use nested elements with the same
  tag name as the attribute name and within the same namespace as
  the dynamic tag:

  <xsp:logic>
    String defaultFormat = "hh:mm:ss aa";
  </xsp:logic>
  .  .  .
  <p>It's now
    <util:time>
      <util:format><xsp:expr>
        defaultFormat
      </xsp:expr></util:format>
    </util:time>
  </p>

The following also works:

  <p>It's now
    <util:time>
      <util:format>
        <request:get-parameter name="format" default="hh:mm:ss">
      </util:format>
    </util:time>
  </p>

where system time would be formatted:

- as specified by the value of the HTTP request parameter "format",
  or
- as "hh:mm:ss" when such parameter is not specified in the request.

---------------------------------------------------------------------
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