wood burning stoves*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Using double slash(//) while using XSLT
 
Similar Threads
XSL 2.0 (looking for ideas)
Extracting XSL content to XML with XSLT problem ...
xslt /xpath issue
XML Transformation
[XSL-FO][docbook]Problem print line in table of contents