xquery error

hi,

while executing below xquery

for $x in doc("Books.xml")/books/book
return if{$x/@category="XML")then<XMLBOOK>{data($x/title)}</XMLBOOK>
else <NONXML>{data($x/title)}</NONXML>


on below xml


<?xml version="1.0" encoding="UTF-8"?>
<books>
	<book category="JAVA">
		<title>Master Core Java</title>
		<author>JG</author>
		<year>2015</year>
		<price>50</price>
	</book>

	<book category="DOTNET">
		<title>Get Certified in .Net</title>
		<author>BG</author>
		<year>2016</year>
		<price>60</price>
	</book>

	<book category="XML">
		<title lang="en">XML and XML Schema Definition in easy steps</title>
		<author>BT</author>
		<year>2014</year>
		<price>20</price>
	</book>

	<book category="XML">
		<title lang="en">XSLT XPATH and XQuery Fundamentals</title>
		<author>BT</author>
		<year>2016</year>
		<price>30</price>
	</book>
</books>

Open in new window

getting below error

Syntax error on line 2 at column 9 of file:/C:/Users/sg/gpJava/ud/xsl_xpath_jquery/XQuery/Books2.xqy near {....xml")/books/book return if...}
  XPST0003: Unrecognized node constructor if{}
Static error(s) in query

how to fix it
please advise
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BigRatCommented:
Replace the curly opening bracket after the "if" with a round opening bracket "(".
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
i will try that
0
gudii9Author Commented:
for $x in doc("Books.xml")/books/book
return if($x/@category="XML")then<XMLBOOK>{data($x/title)}</XMLBOOK>
else <NONXML>{data($x/title)}</NONXML>

it worked as above

in eclipse how to create xpy file??(File -->New -->Other has only option to create xml though..do i need separate plug in for this?)


As of now i just imported unzipped folder as existinng project.

then i clicked on the xqy file and run --->run as--->run configuration

there in main

i searched on Query selected
net.sf.saxon.Query

(not sure why it showed same entries two times any way i selected one of them)

In arguments i gave Books2.xpy the same xquery file name i am runing

when i apply and run console gave the result of the filtered data

<?xml version="1.0" encoding="UTF-8"?><NONXML>Master Core Java</NONXML><NONXML>Get Certified in .Net</NONXML><XMLBOOK>XML and XML Schema Definition in easy steps</XMLBOOK><XMLBOOK>XSLT XPATH and XQuery Fundamentals</XMLBOOK>
xquery1.png
xquery2.png
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

BigRatCommented:
If you mean create an XQuery file in Eclipse, then yes you need a plugin.
The details are here https://wiki.eclipse.org/New_Eclipse_Plugin_for_XQuery

I have no idea what an "xpy" file is?
0
gudii9Author Commented:
I have no idea what an "xpy" file is?
i mean xqy which is short cut for xquery
what is the name of the plug in to search on eclipse market place? please advise
0
BigRatCommented:
Sorry, but it beats me how one can abbreviate XQuery in a way that a "p" turns up in the string.

All the information you need for an XQuery Plug-in for Eclipse is in the link I gave you.
0
gudii9Author Commented:
i need to try on personal laptop
0
BigRatCommented:
Ok, so install Eclipse on the LapTop, follow the link and download the plugin.
0
BigRatCommented:
ID: 42371199 confirms the answer provided to the question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.