jQuery in Action, 3rd edition
The moose likes XML and Related Technologies and the fly likes Using double slash(//) while using XSLT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Using double slash(//) while using XSLT" Watch "Using double slash(//) while using XSLT" New topic
Author

Using double slash(//) while using XSLT

Daksh Mital
Greenhorn

Joined: Aug 19, 2007
Posts: 19
Hi
I have an XML file which i am parsing using XSLT
The sample of the XML file is like ( only small part being shown here)

The <block> element inside has its own children.
I want to check inside the block element whether a particular node
<selectValue>

exists or not

The XSLT which I have written is

Now inside <xsl:value-of select="count(//selectValue)"/> when I use count(//selectValue) it gives me all the count which are present in the whole XML structure,which i don't want

I want the count of selectValue which are there somewhere down in hierarchy of <contents> -> <block> -> <contents>

Is this achievable??I need help immediately
Thanks & Regard


Daksh
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19719
    
  10

You are looking for all selectValue elements which are descendants of the document element, as you can see. But if I understand it right, you actually only want to look for selectValue elements which are descendants of the context node. The XPath expression for the context node is "." so you do that like this:

Note that you don't need to count the elements; the expression ".//selectValue" returns a nodeset containing all the selectValue elements which are descendants of the context node, and coercing that to boolean produces false if the nodeset is empty and true if it isn't.
>
Daksh Mital
Greenhorn

Joined: Aug 19, 2007
Posts: 19
Hi
Paul thanks a lot for help
Cheers
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Using double slash(//) while using XSLT
 
It's not a secret anymore!