xsltbasex

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!!!

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 !


Solution

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

    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)
    

    (no wrapping <query><text>), 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 <text> element. To achieve that you will need to escape the contained elements, typically by wrapping them in a CDATA section:

    <query><text><![CDATA[
        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>