Dynamically loading XQueries

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamically loading XQueries

Daniel E. Renfer
Dear fellow OPS users,

I'm having a bit of trouble getting my application working the way I
want it to, and I was wondering if anyone had any tips to help me out.

First, let me give you a quick overview of how my url's are currently
laid out. The root of my application is currently located at:
http://work.kronkltd.net/ops/mycyclopedia/ Every "page" is going to be
content-negotiated (depending on request parameters) and you can add
extra paths to select a certain type to be returned.

for instance:
/entry/44                                 ` returns content-negotiated
version of page. (usually XHTML)
/entry/44/xhtml                        ` XHTML version of page
/entry/44/atom                         ` ATOM version of page
/entry/44/xml                           ` XML version of page.
(usually model for page)

and then you can also add other keywords to select sub-pages (each
with it's own level of content tags)

/entry/44/children                     ` children of entry #44
/entry/44/children/atom             ` Atom version of children of #44
/entry/263/lived/xhtml                ` XHTML version of places #263 has lived

Instead of repeating the exact same code over and over again, I
reluctantly decided to generate part of my page flow using an xslt
stylesheet. I'm now having a problem loading a different XQuery based
on the 'mode' element in my submission (loaded from the 3rd path group
via regex)

Basically, the only way I could think of to do it is to have two
different transformations. One, to set the name of the query to be
loaded, and the second to insert the value of the $Id variable that
has to be sent to eXist. I'm now having problems getting the
xsl:value-of in my query to come through un-escaped. I was hoping that
someone would have an idea on how to do this, or a better way. If not,
then I think I might just have to see if I can have a go at fixing
bug#304672 [1] and sending in a patch.

My files look somewhat like this:

oxf:/mycyclopedia/model/entry/subpages.xpl

<p:config  xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline">
        <p:param name="instance" type="input"/>
        <p:param name="data" type="output"/>
        <p:processor name="oxf:xslt">
                <p:input name="data" href="#instance"/>
                <p:input name="config" href="oxf:/mycyclopedia/model/entry/entry.xsl"/>
                <p:output name="data" id="pipeline"/>
        </p:processor>
        <p:processor name="oxf:pipeline">
                <p:input name="config" href="#pipeline" debug="pipeline"/>
                <p:output name="data" ref="data"/>
        </p:processor>
</p:config>

oxf:/mycyclopedia/model/entry/entry.xsl

<xsl:stylesheet version="2.0"
        xmlns:myc="http://www.kronkltd.net/mycyclopedia"
        xmlns:oxf="http://www.orbeon.com/oxf/processors"
        xmlns:p="http://www.orbeon.com/oxf/pipeline"
        xmlns:xdb="http://orbeon.org/oxf/xml/xmldb"
        xmlns:xi="http://www.w3.org/2001/XInclude"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="/">
                <p:config>
                        <p:param name="instance" type="input" />
                        <p:param name="data" type="output" />
                       
                        <p:processor name="oxf:url-generator">
                                <p:input name="config">
                                        <config>
                                                <url>oxf:/mycyclopedia/model/xquery/entry/<xsl:value-of
select="/submission/mode"/>.xq</url>
                                                <content-type>text/plain</content-type>
                                                <force-content-type>true</force-content-type>
                                        </config>
                                </p:input>
                                <p:output name="data" id="x"/>
                        </p:processor>
                       
                        <p:processor name="oxf:xslt">
                                <p:input href="#x" name="data" />
                                <p:input name="config">
                                        <xsl:element name="xdb:query">
                                                <xsl:attribute name="collection">/db/kronk/mycyclopedia</xsl:attribute>
                                                <xsl:attribute name="xsl:version">2.0</xsl:attribute>
                                                <xsl:element name="xsl:value-of">
                                                        <xsl:attribute name="select">.</xsl:attribute>
                                                </xsl:element>
                                        </xsl:element>
                                </p:input>
                                <p:output id="xquery" name="data"/>
                        </p:processor>
                       
                        <p:processor name="oxf:xmldb-query">
                                <p:input href="oxf:/mycyclopedia/model/datasource.xml" name="datasource" />
                                <p:input href="#xquery" name="query" />
                                <p:output name="data" ref="data" />
                        </p:processor>
                </p:config>
        </xsl:template>
</xsl:stylesheet>

and an example of an XQuery:
oxf:/mycyclopedia/model/xquery/entry/children.xq

xquery version "1.0";

let
        $Id := <xsl:value-of select="/submission/Id"/>
return
        <myc:root>
        {
                for
                        $person in document("mycyclopedia.xml")//myc:Entry
                where
                        $person/myc:parents/myc:person/@Id = $Id
                return
                        $person
        }
        </myc:root>

Does anyone have any idea as to how I could better do this? I've tried
just about everything I can think of, from @disable-output-escaping to
trying to get the $Id loaded in the same pass. Any help will be
greatly appreciated. (note: if you try to look at what I have, /atom
is the only one that's wired to use the dynamic model, atm)

Daniel E. Renfer (http://kronkltd.net/)


[1]: http://forge.objectweb.org/tracker/index.php?func=detail&aid=304672&group_id=168&atid=350207


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Dynamically loading XQueries

Alessandro  Vernet
Administrator
On 4/12/06, Daniel E. Renfer <[hidden email]> wrote:
> I'm now having problems getting the
> xsl:value-of in my query to come through un-escaped. I was hoping that
> someone would have an idea on how to do this, or a better way. If not,
> then I think I might just have to see if I can have a go at fixing
> bug#304672 [1] and sending in a patch.

Hi Daniel,

I am not sure that is related to bug 304672, or maybe I don't full
understand the problem. Why would you need to escape the id if it is a
number? Just an <xsl:value-of> should do the trick, shouldn't it?
Maybe for security reasons, you might want to check that the id is
just a number (say with a schema) before you run the XQuery.

Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Dynamically loading XQueries

Daniel E. Renfer
After I sent this, I tried it a different way, and now have it
working. (to an extent)

My problem is I was trying to load *.xq files that had xslt statements
inside of them. I was able to load the *.xq file using a url
generator, but I was having trouble both transforming the "document"
element into a "xdb:query" element while allowing the xsl:value-of tag
to come through un-escaped. I finally just gave up and stored the
<xdb:query> tags with all of their relevant namespace declarations
right in the xquery files. Not quite as elegant as I wanted, but it'll
do the trick.

I think I'm probably going to just end up forgetting all about the
xml:db processor altogether and just interface eXist via XQueries
stored in the DB and the REST interface. It seems a lot easier than
not being able to validate my queries because there's a whole bunch of
foreign markup in it.

As far as my Id goes... it comes from a regex that only matches (\d+)
so I don't really have to worry about injection. Or do I?

Daniel E. Renfer (http://kronkltd.net/)

On 4/12/06, Alessandro Vernet <[hidden email]> wrote:

> On 4/12/06, Daniel E. Renfer <[hidden email]> wrote:
> > I'm now having problems getting the
> > xsl:value-of in my query to come through un-escaped. I was hoping that
> > someone would have an idea on how to do this, or a better way. If not,
> > then I think I might just have to see if I can have a go at fixing
> > bug#304672 [1] and sending in a patch.
>
> Hi Daniel,
>
> I am not sure that is related to bug 304672, or maybe I don't full
> understand the problem. Why would you need to escape the id if it is a
> number? Just an <xsl:value-of> should do the trick, shouldn't it?
> Maybe for security reasons, you might want to check that the id is
> just a number (say with a schema) before you run the XQuery.
>
> Alex
> --
> Blog (XML, Web apps, Open Source):
> http://www.orbeon.com/blog/
>
>
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>
>
>


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Dynamically loading XQueries

Alessandro  Vernet
Administrator
On 4/12/06, Daniel E. Renfer <[hidden email]> wrote:
> As far as my Id goes... it comes from a regex that only matches (\d+)
> so I don't really have to worry about injection. Or do I?

Hi Daniel,

Yes, in this case you should be safe.

Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet