You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Grzegorz Zuber <zu...@gmail.com> on 2015/10/29 09:11:38 UTC

XQuery or XSLT support in Derby

Hi,

I was doing wide research how can I do XQuery or XSLT query using Derby.

I'm doing query like this:



SELECT
    XMLSERIALIZE(
        XMLQUERY('<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="
http://www.w3.org/1999/XSL/Format">

    <xsl:template match="catalog">
        <html lang="en">
            <head>
            <body>

                <table>
                    <thead>
                        <tr>
                            <th>Title</th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="book">
                            <tr>
                                <td>
                                    <xsl:value-of select="title" />
                                </td>
                            </tr>
                        </xsl:for-each>
                    </tbody>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>' PASSING BY REF xml_col EMPTY ON
        EMPTY) AS VARCHAR(10)
    )AS ProductId
FROM xml_orders




But I'm getting an exception:

java.sql.SQLException: Encountered error while evaluating XML query
expression for xmlquery operator:
com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
Prefix must resolve to a namespace: xsl
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
Source)
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
at
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown
Source)
at
org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown
Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown
Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown
Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
at com.sqlxd.derby.DBQuery.executeDerbyQuery(DBQuery.java:295)
at com.SQLxDClient.QueryExecutor.executeQuery(QueryExecutor.java:47)
at com.SQLxDClient.Window$3.serveExecuteToGrid(Window.java:204)
at com.SQLxDClient.Window$3.mouseClicked(Window.java:192)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
at java.awt.Component.processMouseEvent(Component.java:6519)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4501)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:706)
at java.awt.EventQueue$3.run(EventQueue.java:704)
at java.security.AccessController.doPrivileged(Native Method)
at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:720)
at java.awt.EventQueue$4.run(EventQueue.java:718)
at java.security.AccessController.doPrivileged(Native Method)
at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: ERROR 10000: Encountered error while evaluating XML query
expression for xmlquery operator:
com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
Prefix must resolve to a namespace: xsl
at org.apache.derby.iapi.error.StandardException.newException(Unknown
Source)
at
org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
Source)
... 45 more
Caused by: javax.xml.xpath.XPathExpressionException:
com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
Prefix must resolve to a namespace: xsl
at
com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:400)
at org.apache.derby.iapi.types.SqlXmlUtil.compileXQExpr(Unknown Source)
at
org.apache.derby.exe.ac185e801cx0150xb293xf5c3x000006bfe7b80.postConstructor(Unknown
Source)
at
org.apache.derby.impl.services.reflect.LoadedGeneratedClass.newInstance(Unknown
Source)
at org.apache.derby.impl.sql.GenericActivationHolder.<init>(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.getActivation(Unknown
Source)
... 38 more
Caused by:
com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
Prefix must resolve to a namespace: xsl
at
com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3(XPathParser.java:657)
at
com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:642)
at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:219)
at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:100)
at
com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:114)
at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:180)
at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:268)
at
com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:392)
... 43 more


How can I avoid that?



Thank you,
Greg

Re: XQuery or XSLT support in Derby

Posted by Grzegorz Zuber <zu...@gmail.com>.
Dear Peter,


Thank you for your answer.

I have XML stored in my database.

XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<orders>
   <singleOrder no="1" date="2015-01-22">
      <customer id="1" />
      <products>
         <product>
            <productId>1</productId>
            <orderId>1</orderId>
            <quantity>3</quantity>
         </product>
      </products>
   </singleOrder>
   <singleOrder no="4" date="2015-02-27">
      <customer id="1" />
      <products>
         <product>
            <productId>3</productId>
           <orderId>4</orderId>
            <quantity>2</quantity>
         </product>
         <product>
            <productId>4</productId>
           <orderId>4</orderId>
            <quantity>4</quantity>
         </product>
      </products>
   </singleOrder>
   <singleOrder no="2" date="2015-01-25">
      <customer id="3" />
      <products>
         <product>
            <productId>4</productId>
           <orderId>2</orderId>
            <quantity>5</quantity>
         </product>
      </products>
   </singleOrder>
   <singleOrder no="3" date="2015-02-01">
      <customer id="4" />
      <products>
         <product>
            <productId>1</productId>
           <orderId>3</orderId>
            <quantity>8</quantity>
         </product>
         <product>
            <productId>3</productId>
           <orderId>3</orderId>
            <quantity>20</quantity>
         </product>
      </products>
   </singleOrder>
</orders>



I want to get from it for all product: customer/@id, singleOrder/@no,
productId, quantity, singleOrder/@date, so the output will look like this:


customerIdorderIdproductIdquantitydate11132015-01-2214322015-02-271444
2015-02-2732452015-01-2543182015-02-01433202015-02-01

Do you know how to do that?


Thank you,
Grzegorz


2015-10-29 13:51 GMT+01:00 Peter Ondruška <pe...@kaibo.eu>:

> Dear Greg,
>
> unless anything changed with last Derby release XML support in Derby is
> limited to storing XML--the last time I checked basically there is only an
> XML data type, no query, no indexes.
>
> On 29 October 2015 at 09:11, Grzegorz Zuber <zu...@gmail.com>
> wrote:
>
>> Hi,
>>
>> I was doing wide research how can I do XQuery or XSLT query using Derby.
>>
>> I'm doing query like this:
>>
>>
>>
>> SELECT
>>     XMLSERIALIZE(
>>         XMLQUERY('<?xml version="1.0" encoding="UTF-8"?>
>> <xsl:stylesheet version="1.0"
>>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="
>> http://www.w3.org/1999/XSL/Format">
>>
>>     <xsl:template match="catalog">
>>         <html lang="en">
>>             <head>
>>             <body>
>>
>>                 <table>
>>                     <thead>
>>                         <tr>
>>                             <th>Title</th>
>>                         </tr>
>>                     </thead>
>>                     <tbody>
>>                         <xsl:for-each select="book">
>>                             <tr>
>>                                 <td>
>>                                     <xsl:value-of select="title" />
>>                                 </td>
>>                             </tr>
>>                         </xsl:for-each>
>>                     </tbody>
>>                 </table>
>>             </body>
>>         </html>
>>     </xsl:template>
>> </xsl:stylesheet>' PASSING BY REF xml_col EMPTY ON
>>         EMPTY) AS VARCHAR(10)
>>     )AS ProductId
>> FROM xml_orders
>>
>>
>>
>>
>> But I'm getting an exception:
>>
>> java.sql.SQLException: Encountered error while evaluating XML query
>> expression for xmlquery operator:
>> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
>> Prefix must resolve to a namespace: xsl
>> at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
>> Source)
>> at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
>> Source)
>> at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>> at
>> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown
>> Source)
>> at
>> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown
>> Source)
>> at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown
>> Source)
>> at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown
>> Source)
>> at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
>> at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
>> at com.sqlxd.derby.DBQuery.executeDerbyQuery(DBQuery.java:295)
>> at com.SQLxDClient.QueryExecutor.executeQuery(QueryExecutor.java:47)
>> at com.SQLxDClient.Window$3.serveExecuteToGrid(Window.java:204)
>> at com.SQLxDClient.Window$3.mouseClicked(Window.java:192)
>> at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
>> at java.awt.Component.processMouseEvent(Component.java:6519)
>> at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
>> at java.awt.Component.processEvent(Component.java:6281)
>> at java.awt.Container.processEvent(Container.java:2229)
>> at java.awt.Component.dispatchEventImpl(Component.java:4872)
>> at java.awt.Container.dispatchEventImpl(Container.java:2287)
>> at java.awt.Component.dispatchEvent(Component.java:4698)
>> at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
>> at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4501)
>> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
>> at java.awt.Container.dispatchEventImpl(Container.java:2273)
>> at java.awt.Window.dispatchEventImpl(Window.java:2719)
>> at java.awt.Component.dispatchEvent(Component.java:4698)
>> at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
>> at java.awt.EventQueue.access$300(EventQueue.java:103)
>> at java.awt.EventQueue$3.run(EventQueue.java:706)
>> at java.awt.EventQueue$3.run(EventQueue.java:704)
>> at java.security.AccessController.doPrivileged(Native Method)
>> at
>> java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
>> at
>> java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
>> at java.awt.EventQueue$4.run(EventQueue.java:720)
>> at java.awt.EventQueue$4.run(EventQueue.java:718)
>> at java.security.AccessController.doPrivileged(Native Method)
>> at
>> java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
>> at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
>> at
>> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
>> at
>> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
>> at
>> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
>> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
>> at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
>> Caused by: ERROR 10000: Encountered error while evaluating XML query
>> expression for xmlquery operator:
>> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
>> Prefix must resolve to a namespace: xsl
>> at org.apache.derby.iapi.error.StandardException.newException(Unknown
>> Source)
>> at
>> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>> Source)
>> ... 45 more
>> Caused by: javax.xml.xpath.XPathExpressionException:
>> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
>> Prefix must resolve to a namespace: xsl
>> at
>> com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:400)
>> at org.apache.derby.iapi.types.SqlXmlUtil.compileXQExpr(Unknown Source)
>> at
>> org.apache.derby.exe.ac185e801cx0150xb293xf5c3x000006bfe7b80.postConstructor(Unknown
>> Source)
>> at
>> org.apache.derby.impl.services.reflect.LoadedGeneratedClass.newInstance(Unknown
>> Source)
>> at org.apache.derby.impl.sql.GenericActivationHolder.<init>(Unknown
>> Source)
>> at
>> org.apache.derby.impl.sql.GenericPreparedStatement.getActivation(Unknown
>> Source)
>> ... 38 more
>> Caused by:
>> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
>> Prefix must resolve to a namespace: xsl
>> at
>> com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3(XPathParser.java:657)
>> at
>> com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:642)
>> at
>> com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:219)
>> at
>> com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:100)
>> at
>> com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:114)
>> at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:180)
>> at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:268)
>> at
>> com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:392)
>> ... 43 more
>>
>>
>> How can I avoid that?
>>
>>
>>
>> Thank you,
>> Greg
>>
>
>
>
> --
> Peter Ondruška
>

Re: XQuery or XSLT support in Derby

Posted by Peter Ondruška <pe...@kaibo.eu>.
Dear Greg,

unless anything changed with last Derby release XML support in Derby is
limited to storing XML--the last time I checked basically there is only an
XML data type, no query, no indexes.

On 29 October 2015 at 09:11, Grzegorz Zuber <zu...@gmail.com> wrote:

> Hi,
>
> I was doing wide research how can I do XQuery or XSLT query using Derby.
>
> I'm doing query like this:
>
>
>
> SELECT
>     XMLSERIALIZE(
>         XMLQUERY('<?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="
> http://www.w3.org/1999/XSL/Format">
>
>     <xsl:template match="catalog">
>         <html lang="en">
>             <head>
>             <body>
>
>                 <table>
>                     <thead>
>                         <tr>
>                             <th>Title</th>
>                         </tr>
>                     </thead>
>                     <tbody>
>                         <xsl:for-each select="book">
>                             <tr>
>                                 <td>
>                                     <xsl:value-of select="title" />
>                                 </td>
>                             </tr>
>                         </xsl:for-each>
>                     </tbody>
>                 </table>
>             </body>
>         </html>
>     </xsl:template>
> </xsl:stylesheet>' PASSING BY REF xml_col EMPTY ON
>         EMPTY) AS VARCHAR(10)
>     )AS ProductId
> FROM xml_orders
>
>
>
>
> But I'm getting an exception:
>
> java.sql.SQLException: Encountered error while evaluating XML query
> expression for xmlquery operator:
> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
> Prefix must resolve to a namespace: xsl
> at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
> at
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown
> Source)
> at
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
> at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
> at com.sqlxd.derby.DBQuery.executeDerbyQuery(DBQuery.java:295)
> at com.SQLxDClient.QueryExecutor.executeQuery(QueryExecutor.java:47)
> at com.SQLxDClient.Window$3.serveExecuteToGrid(Window.java:204)
> at com.SQLxDClient.Window$3.mouseClicked(Window.java:192)
> at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
> at java.awt.Component.processMouseEvent(Component.java:6519)
> at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
> at java.awt.Component.processEvent(Component.java:6281)
> at java.awt.Container.processEvent(Container.java:2229)
> at java.awt.Component.dispatchEventImpl(Component.java:4872)
> at java.awt.Container.dispatchEventImpl(Container.java:2287)
> at java.awt.Component.dispatchEvent(Component.java:4698)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
> at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4501)
> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
> at java.awt.Container.dispatchEventImpl(Container.java:2273)
> at java.awt.Window.dispatchEventImpl(Window.java:2719)
> at java.awt.Component.dispatchEvent(Component.java:4698)
> at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
> at java.awt.EventQueue.access$300(EventQueue.java:103)
> at java.awt.EventQueue$3.run(EventQueue.java:706)
> at java.awt.EventQueue$3.run(EventQueue.java:704)
> at java.security.AccessController.doPrivileged(Native Method)
> at
> java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
> at
> java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
> at java.awt.EventQueue$4.run(EventQueue.java:720)
> at java.awt.EventQueue$4.run(EventQueue.java:718)
> at java.security.AccessController.doPrivileged(Native Method)
> at
> java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
> at
> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
> at
> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
> at
> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
> Caused by: ERROR 10000: Encountered error while evaluating XML query
> expression for xmlquery operator:
> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
> Prefix must resolve to a namespace: xsl
> at org.apache.derby.iapi.error.StandardException.newException(Unknown
> Source)
> at
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
> Source)
> ... 45 more
> Caused by: javax.xml.xpath.XPathExpressionException:
> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
> Prefix must resolve to a namespace: xsl
> at
> com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:400)
> at org.apache.derby.iapi.types.SqlXmlUtil.compileXQExpr(Unknown Source)
> at
> org.apache.derby.exe.ac185e801cx0150xb293xf5c3x000006bfe7b80.postConstructor(Unknown
> Source)
> at
> org.apache.derby.impl.services.reflect.LoadedGeneratedClass.newInstance(Unknown
> Source)
> at org.apache.derby.impl.sql.GenericActivationHolder.<init>(Unknown Source)
> at
> org.apache.derby.impl.sql.GenericPreparedStatement.getActivation(Unknown
> Source)
> ... 38 more
> Caused by:
> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
> Prefix must resolve to a namespace: xsl
> at
> com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3(XPathParser.java:657)
> at
> com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:642)
> at
> com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:219)
> at
> com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:100)
> at
> com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:114)
> at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:180)
> at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:268)
> at
> com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:392)
> ... 43 more
>
>
> How can I avoid that?
>
>
>
> Thank you,
> Greg
>



-- 
Peter Ondruška

Re: XQuery or XSLT support in Derby

Posted by Knut Anders Hatlen <kn...@oracle.com>.
Grzegorz Zuber <zu...@gmail.com> writes:

> Hi,
>
> I was doing wide research how can I do XQuery or XSLT query using
> Derby.
>
> I'm doing query like this:
>
> SELECT
> XMLSERIALIZE(
> XMLQUERY('<?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
>
> <xsl:template match="catalog">
> <html lang="en">
> <head>
> <body>
>
> <table>
> <thead>
> <tr>
> <th>Title</th>
> </tr>
> </thead>
> <tbody>
> <xsl:for-each select="book">
> <tr>
> <td>
> <xsl:value-of select="title" />
> </td>
> </tr>
> </xsl:for-each>
> </tbody>
> </table>
> </body>
> </html>
> </xsl:template>
> </xsl:stylesheet>' PASSING BY REF xml_col EMPTY ON
> EMPTY) AS VARCHAR(10)
> )AS ProductId
> FROM xml_orders
>
> But I'm getting an exception:
>
> java.sql.SQLException: Encountered error while evaluating XML query
> expression for xmlquery operator:
> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
> Prefix must resolve to a namespace: xsl
> at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException
> (Unknown Source)
> at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException
> (Unknown Source)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
> at
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException
> (Unknown Source)
> at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException
> (Unknown Source)
> at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
> at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown
> Source)
> at com.sqlxd.derby.DBQuery.executeDerbyQuery(DBQuery.java:295)
> at com.SQLxDClient.QueryExecutor.executeQuery(QueryExecutor.java:47)
> at com.SQLxDClient.Window$3.serveExecuteToGrid(Window.java:204)
> at com.SQLxDClient.Window$3.mouseClicked(Window.java:192)
> at java.awt.AWTEventMulticaster.mouseClicked
> (AWTEventMulticaster.java:270)
> at java.awt.Component.processMouseEvent(Component.java:6519)
> at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
> at java.awt.Component.processEvent(Component.java:6281)
> at java.awt.Container.processEvent(Container.java:2229)
> at java.awt.Component.dispatchEventImpl(Component.java:4872)
> at java.awt.Container.dispatchEventImpl(Container.java:2287)
> at java.awt.Component.dispatchEvent(Component.java:4698)
> at java.awt.LightweightDispatcher.retargetMouseEvent
> (Container.java:4832)
> at java.awt.LightweightDispatcher.processMouseEvent
> (Container.java:4501)
> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
> at java.awt.Container.dispatchEventImpl(Container.java:2273)
> at java.awt.Window.dispatchEventImpl(Window.java:2719)
> at java.awt.Component.dispatchEvent(Component.java:4698)
> at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
> at java.awt.EventQueue.access$300(EventQueue.java:103)
> at java.awt.EventQueue$3.run(EventQueue.java:706)
> at java.awt.EventQueue$3.run(EventQueue.java:704)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.security.ProtectionDomain$1.doIntersectionPrivilege
> (ProtectionDomain.java:76)
> at java.security.ProtectionDomain$1.doIntersectionPrivilege
> (ProtectionDomain.java:87)
> at java.awt.EventQueue$4.run(EventQueue.java:720)
> at java.awt.EventQueue$4.run(EventQueue.java:718)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.security.ProtectionDomain$1.doIntersectionPrivilege
> (ProtectionDomain.java:76)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
> at java.awt.EventDispatchThread.pumpOneEventForFilters
> (EventDispatchThread.java:242)
> at java.awt.EventDispatchThread.pumpEventsForFilter
> (EventDispatchThread.java:161)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy
> (EventDispatchThread.java:150)
> at java.awt.EventDispatchThread.pumpEvents
> (EventDispatchThread.java:146)
> at java.awt.EventDispatchThread.pumpEvents
> (EventDispatchThread.java:138)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
> Caused by: ERROR 10000: Encountered error while evaluating XML query
> expression for xmlquery operator:
> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
> Prefix must resolve to a namespace: xsl
> at org.apache.derby.iapi.error.StandardException.newException(Unknown
> Source)
> at
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
> Source)
> ... 45 more
> Caused by: javax.xml.xpath.XPathExpressionException:
> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
> Prefix must resolve to a namespace: xsl
> at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile
> (XPathImpl.java:400)
> at org.apache.derby.iapi.types.SqlXmlUtil.compileXQExpr(Unknown
> Source)
> at
> org.apache.derby.exe.ac185e801cx0150xb293xf5c3x000006bfe7b80.postConstructor(Unknown
> Source)
> at
> org.apache.derby.impl.services.reflect.LoadedGeneratedClass.newInstance(Unknown
> Source)
> at org.apache.derby.impl.sql.GenericActivationHolder.<init>(Unknown
> Source)
> at org.apache.derby.impl.sql.GenericPreparedStatement.getActivation
> (Unknown Source)
> ... 38 more
> Caused by:
> com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
> Prefix must resolve to a namespace: xsl
> at com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3
> (XPathParser.java:657)
> at com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens
> (Lexer.java:642)
> at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize
> (Lexer.java:219)
> at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize
> (Lexer.java:100)
> at com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath
> (XPathParser.java:114)
> at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:180)
> at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:268)
> at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile
> (XPathImpl.java:392)
> ... 43 more
>
> How can I avoid that?
>
> Thank you,
> Greg

Hi Greg,

Derby's XMLQUERY operator only supports the XPath query language at the
moment, whereas your example seems to use some other query language. I
think you can achieve something similar with an XPath query such as this
one:

SELECT XMLSERIALIZE(XMLQUERY('//book/title' PASSING BY REF xml_col EMPTY ON EMPTY) AS VARCHAR(100)) FROM xml_orders;

Hope this helps,

-- 
Knut Anders