Grzegorz Zuber <zubergrzes...@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

Reply via email to