[xquery-talk] let's comment out a line in XQuery

Michael Kay mike at saxonica.com
Thu Dec 20 08:00:09 PST 2012


Your problem is the call

concat($f/*:Placemark[$c]//*:coordinates/text(), ...

The first argument selects more than one text node, but the arguments to concat() must be single items.

Note that you haven't actually commented anything out. When you change the content of an element constructor from

<a> <b/> <c/> </a>

to

<a> (:<b/>:) <c/> </a>

the content of the <a> element will be a text node containing " (:", an empty b element, a text node containing ":) ", an empty <c/> element, and possibly (depending on boundary-space settings) a text node containing a single space. This is because comment delimiters are not recognized inside literal element content.

The use of /text() in this way is generally a bad habit. Normally if you want the value of the coordinates element, it's best just to atomize the element. You should only use text() if you want to pick out the text nodes from among the other children of the element.

Michael Kay
Saxonica



On 20/12/2012 15:39, jidanni at jidanni.org wrote:
> I don't have a Senior Secondary Certificate of Education :-) but here
> goes anyway. basex: Debian's 7.3-1.
> $ basex noise0.xq |wc
> Stopped at line 26, column 46 in /home/jidanni/mapping/kml/noise0.xq:
> [XPTY0004] Single item expected, ( ALLOW ME TO COMMENT OUT THIS LINE, ...) found.
>        0       0       0
> $ cat noise0.xq
> (:
> # Make a map of noisy neighbors, Xquery version.
> # Copyright       : http://www.fsf.org/copyleft/gpl.html
> # Author          : Dan Jacobson -- http://jidanni.org/
> # Created On      : Sat Jan 29 17:28:12 2011
> # Last Modified On: Thu Dec 20 23:29:24 2012
> # Update Count    : 122
> :)
> declare option output:omit-xml-declaration "no";
> declare function local:fol($f){
>    (: just adds lines between the first point and the rest :)
>    <Folder>
>      {$f/*}
>      <Folder>
>        <name>(lines)</name>
>        <open>0</open>
>        {
> 	for $p at $c in $f/*:Placemark
> 	where $c > 1
> 	return
> 	<Placemark>
> 	  <name>{concat($f/*:Placemark[$c]//*:name/text()," to ",
> 	  $f/*:Placemark[ 1]//*:name/text())}</name>
> 	  <LineString>
> 	    <coordinates>{concat($f/*:Placemark[$c]//*:coordinates/text()," ",
> 	    $f/*:Placemark[ 1]//*:coordinates/text())}</coordinates>
> 	  </LineString>
> 	</Placemark>
> }  </Folder>
> </Folder>}
> ;
> <kml xmlns="http://www.opengis.net/kml/2.2">
>    {comment {"Made by noise.xq, will get OVERWRITTEN"}}
>    <Document>
>      <Folder>
>        <name>噪音 Noise</name>
>        <description>http://jidanni.org/me/quiet.html</description>
>        {local:fol(
>        <Folder>
>          <name>慶福街 1-3 Qingfu St.</name>
> 	<Placemark>
> 	  <name>1-3</name>
> 	  <Point>
> 	    (: <coordinates> ALLOW ME TO COMMENT OUT THIS LINE</coordinates> :)
> 	    <coordinates>120.865201,24.181712</coordinates> (: 2012/12 Google satellite :)
> 	  </Point>
> 	</Placemark>
>          <Placemark>
>            <name>Luo Yuntian</name>
>            <Point>
>              <coordinates>120.868205,24.176483</coordinates>
>            </Point>
>          </Placemark>
>          <Placemark>
>            <name>Zhong Guilin</name>
>            <Point>
>              <coordinates>120.866934,24.152642</coordinates>
>            </Point>
>          </Placemark>
>          <Placemark>
>            <name>Maan Nong Zhuang</name>
>            <Point>
>              <coordinates>120.84368,24.17268</coordinates> (: 東勢區慶福里007鄰-東關路147號 :)
>            </Point>
>          </Placemark>
> 	</Folder>)}
> 	{local:fol(
> 	<Folder>
>            <name>慶福街 1-6 Qingfu St.</name>
> 	  <Placemark>
> 	    <name>1-6</name>
> 	    <Point>
> 	      <coordinates>120.866215,24.181668</coordinates>
> 	    </Point>
> 	  </Placemark>
>            <Placemark>
>              <name>Liu Shiqing</name>
>              <Point>
>                <coordinates>120.86981,24.19667</coordinates> (: Approx :)
>              </Point>
>            </Placemark>
>            <Placemark>
>              <name>Wu Yuxuan</name>
>              <Point>
>                <coordinates>120.86981,24.18811</coordinates>
>              </Point>
>            </Placemark>
>            <Placemark>
>              <name>Chen Chunlai</name>
>              <Point>
>                <coordinates>120.877008,24.187393</coordinates>
>              </Point>
>            </Placemark>
>            <Placemark>
>              <name>Chen Zhenfeng</name>
>              <Point>
>                <coordinates>120.87456,24.18333</coordinates>
>              </Point>
>            </Placemark>
>            <Placemark>
>              <name>Dazhong</name>
>              <Point>
>                <coordinates>120.872499,24.200025</coordinates>
>              </Point>
>            </Placemark>
>            <Placemark>
>              <name>Liu Jinxing</name>
>              <Point>
>                <coordinates>120.874624,24.193282</coordinates>
>              </Point>
>            </Placemark>
>            <Placemark>
>              <name>Zeng Pingzhu</name>
>              <Point>
>                <coordinates>120.868530,24.183716</coordinates>
>              </Point>
>            </Placemark>
> 	  </Folder>)}
>      </Folder>
>    </Document>
> </kml>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list