Hi Elisa

> I used:
> <xtags:variable id="total"
> select="count(//item[title=$Criteria])"/>
> The total is <%= total %>
> ---
> However, "The total is 1.0" is displayed.  I did not expect a
> decimal display for a count value.  Is this something that can be
> changed in xtags?

Unfortunately thats how doubles come out by default.

A quick fix would be to specify the type of the variable as being a number
or Double, then you can output the integer value. e.g.

    <xtags:variable id="total" type="number"
select="count(//item[title=$Criteria])"/>
    The total is <%= total.intValue() %>

or

    <xtags:variable id="total" type="java.lang.Double"
select="count(//item[title=$Criteria])"/>
    The total is <%= total.intValue() %>

Or you could use the i18n tags to format the number.

    <xtags:variable id="total" select="count(//item[title=$Criteria])"/>
    <i18n:formatNumber value="<%= total %>"/>

or
    <i18n:formatNumber value="<%= total %>" pattern="#,###"/>

There are alternative formatters available such as:-

    <i18n:formatCurreny value="<%= total %>"/>
    <i18n:formatPercent value="<%= total %>"/>

if ever you need to output percents or currencies.

For example you might one day wish to do the following:-

    <xtags:variable id="cost" type="number" select="sum(//order/amount)"/>
    <i18n:formatCurreny value="<%= cost %>"/>

James

----- Original Message -----
From: "Elisa Green" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, June 25, 2001 4:30 PM
Subject: Re: xtags questions


>
> To work around this, I went back to the forEach loop.
>
> <xtags:forEach select="//item">
>     <xtags:if test="./title=$Criteria">
>         <% totalcount++; %>
>     </xtags:if>
> </xtags:forEach>
>
> It's not as pretty, but it works.
>
> Elisa
>
> > In XTags all page, request, session and application scope attributes, as
> > well as parameters are all available as XPath variables.
> >
> > So you can do the following:
> >
> > <xtags:parse id="data" uri="xml/mydata.xml"/>
> > <xtags:forEach select="//item">
> >     <xtags:if test="./title=$Criteria'">
> >         <% totalcount++; %>
> >     </xtags:if>
> > </xtags:forEach>
> >
> > Though the above could be done as
> >
> > <xtags:parse id="data" uri="xml/mydata.xml"/>
> > The total is
> > <b>
> > <xtags:valueOf select="count(//item[title=$Criteria])"/>
> > </b>
> >
> > Or a scripting variable could be declared
> >
> > <xtags:variable id="total" select="count(//item[title=$Criteria])"/>
> > The total is <%= total %>
> >
> > > I am trying to build a search results page using xtags in JSP and
> > > would like to count the number of items from my parsed data which
> > > match the input search string (criteriaIn).
> > >
> > > My thinking has brought me to the following problem.  I would
> > > like to use criteriaIn to match each item's title, but it does
> > > not behave as I expected.  Is there a way to work around this?
> > > Or more to the point, is there a feature of taglibs that I have
> > > completely overlooked?
> > >
> > > Relevant code:
> > > ------------------
> > > <%!
> > >     String criteriaIn;
> > >     int totalcount;
> > > %>
> > > <%
> > >     totalcount = 0;
> > >     criteriaIn = request.getParameter("Criteria");
> > > %>
> > >
> > > <%@ taglib uri="/WEB-INF/taglibs/xtags.tld" prefix="xtags" %>
> > >
> > > <xtags:parse id="data" uri="xml/mydata.xml"/>
> > > <xtags:forEach select="//item">
> > >     <xtags:if test="./title='<%= criteriaIn %>'"><% totalcount++;
> > > %></xtags:if>
> > > </xtags:forEach>
> > > -------------------
> > > If a fixed string is used, as the following sample demonstrates,
> > > it works as expected.
> > >
> > > ---------------
> > > <xtags:parse id="data" uri="xml/mydata.xml"/>
> > > <xtags:forEach select="//item">
> > >     <xtags:if test="./title='Nootka'"><% totalcount++;
> > > %></xtags:if>
> > > </xtags:forEach>
> > > ----------------
> > >
> > > Any help will be appreciated.  Is there any good references for
> > > JSP & Taglibs combined, online?
> > >
> > > Thanks in advance.
> > >
> > > Elisa
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to