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 Rashmi Rubdi <de...@yahoo.com> on 2006/09/08 08:43:31 UTC

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

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?
   
  -Rashmi

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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

Posted by Rashmi Rubdi <de...@yahoo.com>.
Thanks for pointing me to the spec, I was looking for a comprehensive documentation on JSTL's XPath capabilities and didn't know it exists, it looks quite useful and well written.
   
  I'll use JSTL 1.1 XML tags for now since as you mentioned it's officially released and it has XPath capabilities.
   
  -Thanks again for all the help
  Rashmi

Kris Schneider <kr...@dotech.com> wrote:
  Rashmi Rubdi wrote:
> Thanks again for your reply.
> 
> If I'm reading your reply correctly, you are saying that we can evaluate XPath expessions with JSTL 1.1 XML Tags

That's correct. Although there may be some bugs ;-). For details on what 
sort of XML/XPath/XSLT operations are available, do some more reading on 
JSTL. The JSTL 1.1 spec (supported by JSP 2.0) can be found here:

http://jcp.org/aboutJava/communityprocess/final/jsr052/index2.html

You'll be looking for a doc called jstl-1_1-mr2-spec.pdf. It's actually a 
pretty easy read, as specs go, and full of good info.

> I got XTags from here: http://people.apache.org/builds/jakarta-taglibs/nightly/projects/xtags/ , 

That would be a nightly build. I'm pretty sure that's all that's available. 
Not that there's anything wrong with that, I just don't think XTags has 
ever been through the official release process.

> I had to set up my environment with dom4j and jaxen beta jar files in order to use XTags
> 
> I'm not sure if XTags has a user mailing list, I wasn't able to find it. I had some further questions on XTags. 

All of the Jakarta taglibs (http://jakarta.apache.org/taglibs/) use this list.

> Kris Schneider wrote:
> Rashmi Rubdi wrote:
> 
>>Thank you for the solution
>>
>>I never thought of that. I think I could use what you have suggested in cases where I transform the xml with jstl and just need the count of certain node sets.
>>
>>I tried XTags, and it has a rich set of XPath capabilities, I was able to do something more complex like this inside the JSP
>>
>>I wonder if one (JSTL XML Tags) is better than the other(XTags) performance wise, but may be they are just different tools with their own purpose.
> 
> 
> I'm not sure that XTags was ever officially released. I assume you're using 
> one of the nightly builds. The Standard taglib is an implementation of JSTL 
> which has been officially released for both JSTL 1.0 and JSTL 1.1.
> 
> Your original code actually appears to work with Standard 1.0.6 (JSTL 1.0). 
> To support XPath, Standard 1.0 uses Jaxen/SAXPath while Standard 1.1 uses 
> Xalan. It's likely there's a bug in how Standard 1.1 is using Xalan to do 
> its XPath evaluation. I believe XTags uses dom4j.
> 
> 
>>Kris Schneider wrote:
>>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:
>>>
>>>
>>>
>>>Book Title 1
>>>Book Title 2
>>>Book Title 3
>>>Book Title 4
>>>Book Title 5
>>>
>>>
>>>I tried using XPath's count function, inside the JSP page, but it gives 0 instead of 
>>>5 - (the number of book nodes)
>>>
>>>
>>>
>>>
>>>
>>>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):
>>
>>
>>
>>
>>
>>
>>
>>
>>>-Rashmi

-- 
Kris Schneider 
D.O.Tech 

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



 		
---------------------------------
 All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.

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

Posted by Kris Schneider <kr...@dotech.com>.
Rashmi Rubdi wrote:
> Thanks again for your reply.
>    
>   If I'm reading your reply correctly, you are saying that we can evaluate XPath expessions with JSTL 1.1 XML Tags

That's correct. Although there may be some bugs ;-). For details on what 
sort of XML/XPath/XSLT operations are available, do some more reading on 
JSTL. The JSTL 1.1 spec (supported by JSP 2.0) can be found here:

http://jcp.org/aboutJava/communityprocess/final/jsr052/index2.html

You'll be looking for a doc called jstl-1_1-mr2-spec.pdf. It's actually a 
pretty easy read, as specs go, and full of good info.

>   I got XTags from here: http://people.apache.org/builds/jakarta-taglibs/nightly/projects/xtags/ , 

That would be a nightly build. I'm pretty sure that's all that's available. 
Not that there's anything wrong with that, I just don't think XTags has 
ever been through the official release process.

>   I had to set up my environment with dom4j and jaxen beta jar files in order to use XTags
>    
>   I'm not sure if XTags has a user mailing list, I wasn't able to find it. I had some further questions on XTags. 

All of the Jakarta taglibs (http://jakarta.apache.org/taglibs/) use this list.

> Kris Schneider <kr...@dotech.com> wrote:
>   Rashmi Rubdi wrote:
> 
>>Thank you for the solution
>>
>>I never thought of that. I think I could use what you have suggested in cases where I transform the xml with jstl and just need the count of certain node sets.
>>
>>I tried XTags, and it has a rich set of XPath capabilities, I was able to do something more complex like this inside the JSP
>>
>>I wonder if one (JSTL XML Tags) is better than the other(XTags) performance wise, but may be they are just different tools with their own purpose.
> 
> 
> I'm not sure that XTags was ever officially released. I assume you're using 
> one of the nightly builds. The Standard taglib is an implementation of JSTL 
> which has been officially released for both JSTL 1.0 and JSTL 1.1.
> 
> Your original code actually appears to work with Standard 1.0.6 (JSTL 1.0). 
> To support XPath, Standard 1.0 uses Jaxen/SAXPath while Standard 1.1 uses 
> Xalan. It's likely there's a bug in how Standard 1.1 is using Xalan to do 
> its XPath evaluation. I believe XTags uses dom4j.
> 
> 
>>Kris Schneider wrote:
>>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:
>>>
>>>
>>>
>>>Book Title 1
>>>Book Title 2
>>>Book Title 3
>>>Book Title 4
>>>Book Title 5
>>>
>>>
>>>I tried using XPath's count function, inside the JSP page, but it gives 0 instead of 
>>>5 - (the number of book nodes)
>>>
>>>
>>>
>>>
>>>
>>>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):
>>
>>
>>
>>
>>
>>
>>
>>
>>>-Rashmi

-- 
Kris Schneider <ma...@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


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

Posted by Rashmi Rubdi <de...@yahoo.com>.
Thanks again for your reply.
   
  If I'm reading your reply correctly, you are saying that we can evaluate XPath expessions with JSTL 1.1 XML Tags
   
  I got XTags from here: http://people.apache.org/builds/jakarta-taglibs/nightly/projects/xtags/ , 
   
  I had to set up my environment with dom4j and jaxen beta jar files in order to use XTags
   
  I'm not sure if XTags has a user mailing list, I wasn't able to find it. I had some further questions on XTags. 
  

Kris Schneider <kr...@dotech.com> wrote:
  Rashmi Rubdi wrote:
> Thank you for the solution
> 
> I never thought of that. I think I could use what you have suggested in cases where I transform the xml with jstl and just need the count of certain node sets.
> 
> I tried XTags, and it has a rich set of XPath capabilities, I was able to do something more complex like this inside the JSP
> 
> I wonder if one (JSTL XML Tags) is better than the other(XTags) performance wise, but may be they are just different tools with their own purpose.

I'm not sure that XTags was ever officially released. I assume you're using 
one of the nightly builds. The Standard taglib is an implementation of JSTL 
which has been officially released for both JSTL 1.0 and JSTL 1.1.

Your original code actually appears to work with Standard 1.0.6 (JSTL 1.0). 
To support XPath, Standard 1.0 uses Jaxen/SAXPath while Standard 1.1 uses 
Xalan. It's likely there's a bug in how Standard 1.1 is using Xalan to do 
its XPath evaluation. I believe XTags uses dom4j.

> Kris Schneider wrote:
> 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:
>>
>>
>>
>>Book Title 1
>>Book Title 2
>>Book Title 3
>>Book Title 4
>>Book Title 5
>>
>>
>>I tried using XPath's count function, inside the JSP page, but it gives 0 instead of 
>>5 - (the number of book nodes)
>>
>>
>>
>>
>>
>>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):
> 
> 
> 
> 
> 
> 
> 
>>-Rashmi

-- 
Kris Schneider 
D.O.Tech 

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



 		
---------------------------------
Do you Yahoo!?
 Everyone is raving about the  all-new Yahoo! Mail.

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

Posted by Kris Schneider <kr...@dotech.com>.
Rashmi Rubdi wrote:
> Thank you for the solution
>    
>   I never thought of that. I think I could use what you have suggested in cases where I transform the xml with jstl and just need the count of certain node sets.
>    
>   I tried XTags, and it has a rich set of XPath capabilities, I was able to do something more complex like this <xtags:valueOf select="substring(/Books/Book[${item_position}]/BookTitle, 0, 50)" />  inside the JSP
>    
>   I wonder if one (JSTL XML Tags) is better than the other(XTags) performance wise, but may be they are just different tools with their own purpose.

I'm not sure that XTags was ever officially released. I assume you're using 
one of the nightly builds. The Standard taglib is an implementation of JSTL 
which has been officially released for both JSTL 1.0 and JSTL 1.1.

Your original code actually appears to work with Standard 1.0.6 (JSTL 1.0). 
To support XPath, Standard 1.0 uses Jaxen/SAXPath while Standard 1.1 uses 
Xalan. It's likely there's a bug in how Standard 1.1 is using Xalan to do 
its XPath evaluation. I believe XTags uses dom4j.

> Kris Schneider <kr...@dotech.com> wrote:
>   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:
>>
>>
>>
>>Book Title 1
>>Book Title 2
>>Book Title 3
>>Book Title 4
>>Book Title 5
>>
>>
>>I tried using XPath's count function, inside the JSP page, but it gives 0 instead of 
>>5 - (the number of book nodes)
>>
>>
>>
>>
>>
>>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):
> 
> 
> 
> 
> 
> 
> 
>>-Rashmi

-- 
Kris Schneider <ma...@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


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

Posted by Rashmi Rubdi <de...@yahoo.com>.
Thank you for the solution
   
  I never thought of that. I think I could use what you have suggested in cases where I transform the xml with jstl and just need the count of certain node sets.
   
  I tried XTags, and it has a rich set of XPath capabilities, I was able to do something more complex like this <xtags:valueOf select="substring(/Books/Book[${item_position}]/BookTitle, 0, 50)" />  inside the JSP
   
  I wonder if one (JSTL XML Tags) is better than the other(XTags) performance wise, but may be they are just different tools with their own purpose.

Kris Schneider <kr...@dotech.com> wrote:
  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:
> 
> 
> 
> Book Title 1
> Book Title 2
> Book Title 3
> Book Title 4
> Book Title 5
> 
> 
> I tried using XPath's count function, inside the JSP page, but it gives 0 instead of 
> 5 - (the number of book nodes)
> 
> 
> 
> 
> 
> 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):






> -Rashmi

-- 
Kris Schneider 
D.O.Tech 

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



 		
---------------------------------
Get your email and more, right on the  new Yahoo.com 

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

Posted by Kris Schneider <kr...@dotech.com>.
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 <ma...@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


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

Posted by Rashmi Rubdi <de...@yahoo.com>.
I did a bit more research on this, and came across XTags tag library. 
   
  It might be more suitable for what I'm trying to achieve.
   
  If that's the case, then i'll close this thread.
   
  
Rashmi Rubdi <de...@yahoo.com> 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:



Book Title 1
Book Title 2
Book Title 3
Book Title 4
Book Title 5


I tried using XPath's count function, inside the JSP page, but it gives 0 instead of 
5 - (the number of book nodes)





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?

-Rashmi

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com