Xpath predicates don't work

Xpath predicates don't work

I've reached a show stopper as my application requires access to external data to function, using JSON to XML and/or XML direct input into the ExecuteXpath function. I have been doing some testing with multiple XML files, including using the example XML in the users guide (see below). 

The problem is when trying to filter using predicates, ExecuteXpath does not work at all. Using the example XML (very simple), I set up the xpath within XPath Builder as:

/bookstore/book/year/text()[1]

Which should return the first entry, "1998". However it returns all of the entries for year:

1998-|-2003-|-2006-|-2007

This is the same as when I remove the predicate:

/bookstore/book/year/text()

1998-|-2003-|-2006-|-2007

When I specify the predicate as:

/bookstore/book/year/text()[2]

I would expect to return the second year entry, 2003. However, the query returns zero records.

This is the simplest of tests that I performed, but again, I loaded many different XML files, as well as JSON, and it's always the same. The first entry has ALL of the records, and queries against any other conditions for attributes fails:

/bookstore/book/title/text()[@year='2003'] 

"NO results" is returned after pressing the Execute button in XPath Builder. 

The ONLY predicate that seems to work, is if I use the current context:

/bookstore/book/year/text()[.='2003']

This returns, as expected, "2003"

It appears that ExecuteXpath is not parsing correctly, and not traversing the Node Tress when instructed to do so.


Below is the XML from the Users Guide example that is referenced in this exercise.

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book category="Mathematics">
<title lang="en">Femat's Enigma</title>
<author>Simon Singh</author>
<year>1998</year>
<price>15</price>
</book>

<book category="Business">
<title lang="en">Survival Is Not Enough</title>
<author>Seth Godin</author>
<year>2003</year>
<price>17.88</price>
</book>

<book category="Science">
<title lang="en">The God Delusion</title>
<author>Richard Dawkins</author>
<year>2006</year>
<price>6.98</price>
</book>

<book category="General">
<title lang="en">The Black Swan</title>
<author>Nassim Nicholas Taleb</author>
<year>2007</year>
<price>19.79</price>
</book>

</bookstore>

    Access your files securely from anywhere







                            Zoho Developer Community




                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts





                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner









                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources

                                                                                              Zoho Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ



                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方