Hi, I want to write a comment in the xml I produce with my XQuery. I try to use the comment() function, but each time I want to put something inside the () i have a syntax error.
for example : <test> {comment("test"), let $r := random:integer(100) + 1 for $j in (/*)[$r] return ( $r,$j) } </test>
or (who is more what I want to do)
<test> { let $r := random:integer(100) + 1 for $j in (/*)[$r] return (comment("$r"),$j) } </test>
I don't find any example on how to use the comment function. Anyone have example about that use?
Thanks
Marc
On 07.08.2019 18:52, Marc wrote:
I want to write a comment in the xml I produce with my XQuery. I try to use the comment() function, but each time I want to put something inside the () i have a syntax error.
If you want to create a comment node computed by an expression use comment { expression }
see https://www.w3.org/TR/xquery-31/#doc-xquery31-CompCommentConstructor
So comment { $r } seems to be what you want to do.
Also literal <!— XML comments —> work just like other literal XML, as there is a different syntax for (: XQuery comments :)
XQuery: <comments> <!-- more comments... --> { collection()[1]//comment() } { comment { " last comment " } }</comments> (: XQuery Comment :)
Produced output:
<comments> <!-- more comments... --> <!-- xmlns="http://www.tei-c.org/ns/1.0" namespace removed and root element TEI => TEI.2 to conform to DTD based TEI stylesheets --> <!-- Real PID: <idno type="uva-pid" >uva-lib:2826790</idno> Fake PID: --> <!-- FIXME: figure on p116 & 117: no image and table missing from transcription --> <!-- FIXME: figure on p116 & 117: no image and table missing from transcription --> <!-- last comment --> </comments>
"comment()" is the XPath syntax to match a comment node, not a function that creates comments.
— Steve M.
On Aug 7, 2019, at 1:03 PM, Martin Honnen martin.honnen@gmx.de wrote:
On 07.08.2019 18:52, Marc wrote:
I want to write a comment in the xml I produce with my XQuery. I try to use the comment() function, but each time I want to put something inside the () i have a syntax error.
If you want to create a comment node computed by an expression use comment { expression }
see https://www.w3.org/TR/xquery-31/#doc-xquery31-CompCommentConstructor
So comment { $r } seems to be what you want to do.
Thanks you very much. I use very often the comment() with XSLT, and I confuse it with the "comment" literal of XQuery ! Marc
Le 07/08/2019 à 19:22, Majewski, Steven Dennis (sdm7g) a écrit :
Also literal <!— XML comments —> work just like other literal XML, as there is a different syntax for (: XQuery comments :)
XQuery: <comments> <!-- more comments... --> { collection()[1]//comment() } { comment { " last comment " } }</comments> (: XQuery Comment :)
Produced output:
<comments> <!-- more comments... --> <!-- xmlns="http://www.tei-c.org/ns/1.0" namespace removed and root element TEI => TEI.2 to conform to DTD based TEI stylesheets --> <!-- Real PID: <idno type="uva-pid" >uva-lib:2826790</idno> Fake PID: --> <!-- FIXME: figure on p116 & 117: no image and table missing from transcription --> <!-- FIXME: figure on p116 & 117: no image and table missing from transcription --> <!-- last comment --> </comments>
"comment()" is the XPath syntax to match a comment node, not a function that creates comments.
— Steve M.
On Aug 7, 2019, at 1:03 PM, Martin Honnen martin.honnen@gmx.de wrote:
On 07.08.2019 18:52, Marc wrote:
I want to write a comment in the xml I produce with my XQuery. I try to use the comment() function, but each time I want to put something inside the () i have a syntax error.
If you want to create a comment node computed by an expression use comment { expression }
see https://www.w3.org/TR/xquery-31/#doc-xquery31-CompCommentConstructor
So comment { $r } seems to be what you want to do.
Am 08.08.2019 um 08:46 schrieb Marc:
I use very often the comment() with XSLT, and I confuse it with the "comment" literal of XQuery !
But even in XSLT the use of "comment()" is only for selecting/matching comment nodes (or for declaring a type), not for creating/constructing them. In XSLT you use the xsl:comment instruction to construct a comment node.
basex-talk@mailman.uni-konstanz.de