Query BaseX with xslt module error on [XPST0003] Expecting variable declaration

huangapple go评论64阅读模式
英文:

Query BaseX with xslt module error on [XPST0003] Expecting variable declaration

问题

I'm using xslt module to query BaseX.

<query>
    <text>
        let $xml := doc("/dsn_ext/pcbtestxmldbdata001_test001.xml") 
        let $style := <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" /><xsl:template match="/"><xsl:copy-of select="." /></xsl:template></xsl:stylesheet> 
        return xslt:transform-text($xml,$style)
    </text>
</query>

I do the query on BaseX GUI and it works!!!

BUT! When I do the same query on postman to query BaseX on a remote server by API, it fails!
The error messages are:
Stopped at /srv/basex/webapp, 3/19:
[XPST0003] Expecting variable declaration.

I don't know why this error occurred. Is there anybody who could help me solve this problem?
Help!!!!!!!
My BaseX versions on local and remote are both 9.5.0

I try it on BaseXGUI and it works correctly but when I try it on Postman, then it fails!
I hope the query will work correctly on Postman!

英文:

I'm using xslt module to query BaseX.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;query&gt;&lt;text&gt;
    let $xml := doc(&quot;/dsn_ext/pcbtestxmldbdata001_test001.xml&quot;) 
    let $style := &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;&lt;xsl:output method=&quot;xml&quot; /&gt;&lt;xsl:template match=&quot;/&quot;&gt;&lt;xsl:copy-of select=&quot;.&quot; /&gt;&lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt; 
    return xslt:transform-text($xml,$style)
&lt;/text&gt;
&lt;/query&gt;

<!-- end snippet -->

I do the query on BaseX GUI and it works!!!

enter image description here

BUT! When I do the same query on postman to query BaseX on remote server by api ,it fails!
The error messages are:
Stopped at /srv/basex/webapp, 3/19:
[XPST0003] Expecting variable declaration.

enter image description here

I don't know why this error occured.Is there anybody could help me to solve this problem ?
Help!!!!!!!
My baseX versions on local and remote are both 9.5.0

I try it on BaseXGUI and it works correctly
but when I try it on postman then it fails!
I hope the query will work correctly on postman !

答案1

得分: 0

以下是翻译好的部分:

"The image you show of the BaseX GUI actually shows the query"(你展示的BaseX GUI图像实际上显示的是查询)

"return xslt:transform-text($xml,$style)"(返回xslt:transform-text($xml,$style))

"I don't know Postman but I would expect that it wants the query to be the string value of the <text> element."(我不了解Postman,但我预期它希望查询是<text>元素的字符串值。)

"To achieve that you will need to escape the contained elements, typically by wrapping them in a CDATA section:"(要实现这一点,您需要转义包含的元素,通常通过将它们包装在CDATA部分中:)

"<query><text><![CDATA["(<query><text><![CDATA[)

"</text>"(</text>)

"</query>"(</query>)

英文:

The image you show of the BaseX GUI actually shows the query

let $xml := doc(&quot;/dsn_ext/pcbtestxmldbdata001_test001.xml&quot;) 
    let $style := &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;&lt;xsl:output method=&quot;xml&quot; /&gt;&lt;xsl:template match=&quot;/&quot;&gt;&lt;xsl:copy-of select=&quot;.&quot; /&gt;&lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt; 
    return xslt:transform-text($xml,$style)

(no wrapping &lt;query&gt;&lt;text&gt;), which is a valid query.

I don't know Postman but I would expect that it wants the query to be the string value of the &lt;text&gt; element. To achieve that you will need to escape the contained elements, typically by wrapping them in a CDATA section:

&lt;query&gt;&lt;text&gt;&lt;![CDATA[
    let $xml := doc(&quot;/dsn_ext/pcbtestxmldbdata001_test001.xml&quot;) 
    let $style := &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;&lt;xsl:output method=&quot;xml&quot; /&gt;&lt;xsl:template match=&quot;/&quot;&gt;&lt;xsl:copy-of select=&quot;.&quot; /&gt;&lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt; 
    return xslt:transform-text($xml,$style)
]]&gt;&lt;/text&gt;
&lt;/query&gt;

huangapple
  • 本文由 发表于 2023年1月6日 10:54:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026499.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定