Re: Is it possible to count number of XML nodes in a node-set with JSTL XML tags?

Kris Schneider <[email protected]>
Newsgroups gmane.comp.jakarta.taglibs.user
Message-ID <[email protected]>
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:[email protected]>
D.O.Tech       <http://www.dotech.com/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.