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