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 Elisa Green <el...@sheridanc.on.ca> on 2001/06/22 20:02:20 UTC

xtags questions

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

using XTags and i18n tags (was Re: xtags questions)

Posted by James Strachan <ja...@yahoo.co.uk>.
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" <el...@sheridanc.on.ca>
To: <ta...@jakarta.apache.org>
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


RE: xtags questions

Posted by "William C. Robertson" <in...@bytetherapy.com>.
Elisa, could you have cast your total variable into an integer? 
ie:
The total is <%= (int)total %>

-----Original Message-----
From: elisa@sheridanc.on.ca [mailto:elisa@sheridanc.on.ca]On Behalf Of
Elisa Green
Sent: Monday, June 25, 2001 8:31 AM
To: taglibs-user@jakarta.apache.org
Subject: Re: xtags questions


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?

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

Re: xtags questions

Posted by Elisa Green <el...@sheridanc.on.ca>.
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?

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

Re: xtags questions

Posted by James Strachan <ja...@yahoo.co.uk>.
Hi 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 %>

James
----- Original Message -----
From: "Elisa Green" <el...@sheridanc.on.ca>
To: "Tablib User Group" <ta...@jakarta.apache.org>
Sent: Friday, June 22, 2001 7:02 PM
Subject: xtags questions


> 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