tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Schneider <k...@dotech.com>
Subject Re: Is it possible to count number of XML nodes in a node-set with JSTL XML tags?
Date Fri, 08 Sep 2006 11:47:29 GMT
Rashmi Rubdi wrote:
> I searched for a solution for this but couldn't find an answer.
>    
>   I'm trying to count the number of book nodes from the xml below:
>    
>   <?xml version="1.0" encoding="UTF-8"?>
> <books>
>  <book isbn="212112">Book Title 1</book>
>  <book isbn="212313">Book Title 2</book>
>  <book isbn="343444">Book Title 3</book>
>  <book isbn="343424">Book Title 4</book>
>  <book isbn="656433">Book Title 5</book>
> </books>
>    
>   I tried using XPath's count function, inside the JSP page, but it gives 0 instead of

>   5 - (the number of book nodes)
>   
> <c:import url="books.xml" var="xml" charEncoding="UTF-8" />
> <x:parse doc="${xml}" var="xml_doc" />
> <x:out select="count($xml_doc/books/book)"/>
>    
>   Is it possible to obtain the count of a node set inside a JSP or do I have to first
transform the source XML into another XML which obtains the count and then read the count
from the second XML file?

Hm, this works though (Standard 1.1.2):

<c:import url="books.xml" var="xml" charEncoding="UTF-8" />
<x:parse doc="${xml}" var="xml_doc" />
<x:set var="book" select="$xml_doc/books/book" />
<x:out select="count($book)"/>

>   -Rashmi

-- 
Kris Schneider <mailto:kris@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message