Discussion:
[xquery-talk] flwor expression result
e-letter
2013-12-19 18:24:10 UTC
Permalink
Readers,

According to the xquery specification , the flwor expression (§ 3.8)
syntax has optional parts, i.e. the 'let' part of the clause.
Therefore the following expression was saved as an 'xq' file:

<html>
<body>
<ul>
for $x in fn:doc("xmldatabasefile.xml")/bookstore/book/author
order by $x/author
return $x/author
</ul>
</body>
</html>

This xquery file was processed using jedit xml plug-ins; xml file:

<?xml version="1.0" encoding="utf-8"?>
<!-- Edited by XMLSpy®, taken from http://www.w3schools.com-->
<?xml-stylesheet type='text/xsl" href="xstylesheetexample.xslt" ?>
<bookstore>
<book
category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
...

The output was:

<html>
<body>
<ul>
for $x in fn:doc("xmldatabasefile.xml")/bookstore/book/author
order by $x/author
return $x/author

</ul>
</body>
</html>

The expected output was a list of authors within the html un-ordered
list element. What is my mistake please?
Michael Kay
2013-12-19 19:32:27 UTC
Permalink
If you put an expression inside the content of an element node, it needs to go in curly braces. Otherwise it's just literal element content.

Michael Kay
Saxonica
Post by e-letter
Readers,
According to the xquery specification , the flwor expression (§ 3.8)
syntax has optional parts, i.e. the 'let' part of the clause.
<html>
<body>
<ul>
for $x in fn:doc("xmldatabasefile.xml")/bookstore/book/author
order by $x/author
return $x/author
</ul>
</body>
</html>
<?xml version="1.0" encoding="utf-8"?>
<!-- Edited by XMLSpy®, taken from http://www.w3schools.com-->
<?xml-stylesheet type='text/xsl" href="xstylesheetexample.xslt" ?>
<bookstore>
<book
category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
...
<html>
<body>
<ul>
for $x in fn:doc("xmldatabasefile.xml")/bookstore/book/author
order by $x/author
return $x/author
</ul>
</body>
</html>
The expected output was a list of authors within the html un-ordered
list element. What is my mistake please?
_______________________________________________
http://x-query.com/mailman/listinfo/talk
e-letter
2013-12-19 19:34:15 UTC
Permalink
Post by Michael Kay
If you put an expression inside the content of an element node, it needs to
go in curly braces. Otherwise it's just literal element content.
Yes, understood this from the description of constructors, but did not
assume this was applicable also to these flwor expressions

Loading...