Need to learn how to set up the context in XQuilla and/or Xerces-C

Discussion in 'XML' started by Ramon F Herrera, Jun 8, 2012.

  1. The following question was posted in the Xerces-C and XQilla mailing
    lists, but number of replies I received is zero. Perhaps a kind soul
    can help me?

    Note: This is a follow up to my thread "I guess XPath is not as
    straightforward as I thought..."

    TIA,

    -Ramon
    -----------------------------------------------------------------

    I have been using two XPath implementations, the one from Xerces-C
    (for fast performance with elemental expressions) and XQilla (for full
    expression support). At this point I have some expressions that must
    be evaluated in two steps.

    First query:
    /root/table[@tagname='intermediate_joints']

    The tables (nodes) produced by that query should be set as the new
    context before the next XPath queries are performed.

    How do I set up the context?

    TIA,

    -Ramon

    ps: I am familiar with the code in the file simple-context-item.cpp,
    but could use more help!

    http://xqilla.sourceforge.net/docs/simple-api/simple-context-item_8cpp-example.html
     
    Ramon F Herrera, Jun 8, 2012
    #1
    1. Advertising

  2. Ramon F Herrera

    Simon Wright Guest

    Ramon F Herrera <> writes:

    > I have been using two XPath implementations, the one from Xerces-C
    > (for fast performance with elemental expressions) and XQilla (for full
    > expression support). At this point I have some expressions that must
    > be evaluated in two steps.
    >
    > First query:
    > /root/table[@tagname='intermediate_joints']
    >
    > The tables (nodes) produced by that query should be set as the new
    > context before the next XPath queries are performed.
    >
    > How do I set up the context?


    You can save the first query in a variable:

    <xsl:variable
    name="foo"
    select="/root/table[@tagname='intermediate_joints']"/>

    and then further selections can be written using

    select="$foo/more/selections"
     
    Simon Wright, Jun 8, 2012
    #2
    1. Advertising

  3. On Jun 8, 11:13 am, Simon Wright <> wrote:
    > Ramon F Herrera <> writes:
    >
    > > I have been using two XPath implementations, the one from Xerces-C
    > > (for fast performance with elemental expressions) and XQilla (for full
    > > expression support).  At this point I have some expressions that must
    > > be evaluated in two steps.

    >
    > > First query:
    > > /root/table[@tagname='intermediate_joints']

    >
    > > The tables (nodes) produced by that query should be set as the new
    > > context before the next XPath queries are performed.

    >
    > > How do I set up the context?

    >
    > You can save the first query in a variable:
    >
    >   <xsl:variable
    >     name="foo"
    >     select="/root/table[@tagname='intermediate_joints']"/>
    >
    > and then further selections can be written using
    >
    >   select="$foo/more/selections"


    Thanks, Simon:

    It seems to me that your suggestion is equivalent to the one in the
    thread "".

    /root/table[@tagname='intermediate_joints']/intermediate_joints/
    joint_label

    That solution is not good when you have a lot of similar tables: You
    get too many hits, and you cannot distinguish which one came from what
    ancestor.

    I just learned (in this NG) about "context", something for which I
    never had any need. I was using it only once without even being aware.

    I need to perform an XPath query relative to the current context. Path
    concatenation will not do.

    -Ramon
     
    Ramon F Herrera, Jun 8, 2012
    #3
  4. On Jun 8, 11:13 am, Simon Wright <> wrote:
    > Ramon F Herrera <> writes:
    >
    > > I have been using two XPath implementations, the one from Xerces-C
    > > (for fast performance with elemental expressions) and XQilla (for full
    > > expression support).  At this point I have some expressions that must
    > > be evaluated in two steps.

    >
    > > First query:
    > > /root/table[@tagname='intermediate_joints']

    >
    > > The tables (nodes) produced by that query should be set as the new
    > > context before the next XPath queries are performed.

    >
    > > How do I set up the context?

    >
    > You can save the first query in a variable:
    >
    >   <xsl:variable
    >     name="foo"
    >     select="/root/table[@tagname='intermediate_joints']"/>
    >


    > and then further selections can be written using
    >
    >   select="$foo/more/selections"


    I need something like this:

    select="./more/selections"

    -RFH
     
    Ramon F Herrera, Jun 8, 2012
    #4
  5. I know nothing about XQuilla, so I strongly suggest that you Read The
    Fine Manual (and the sample programs, if any), and/or contact that
    product's support community. Their API almost certainly provides a
    mechanism for evaluating an XPath with a context node returned by a
    previous XPath. This is a standard XPath concept, and any decent
    implementation of full XPath should support it -- but _how_ it supports
    it is up to the implementation.

    (The answer for Xalan-C can be found in the SimpleXPathAPI sample, which
    executes one XPath, and then uses the result of that as the context
    node(s?) for a second XPath. That sounds like exactly what you're asking
    for.)



    --
    Joe Kesselman,
    http://www.love-song-productions.com/people/keshlam/index.html

    {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
    /\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
     
    Joe Kesselman, Jun 8, 2012
    #5
  6. On Jun 8, 1:09 pm, Joe Kesselman <>
    wrote:
    > I know nothing about XQuilla, so I strongly suggest that you
    > Read The Fine Manual (and the sample programs, if any),


    Here's the Fine Manual:

    http://xqilla.sourceforge.net/docs/simple-api/examples.html

    > and/or contact that product's support community.


    [Ramon wrote:]
    "The following question was posted in the Xerces-C and XQilla mailing
    lists, but number of replies I received is zero. Perhaps a kind soul
    can help me?"

    I am about to port all my code to libxml2 (Thanks, Alain!). I noticed
    that -unlike Xerces-C and Xqilla- their mailing list has lots of
    traffic.

    http://www.xmlsoft.org/

    XML seems to be a area where plenty of software is written only to be
    abandoned (Xerces, Xqilla, Xalan, etc.)

    -Thx,

    -Ramon
     
    Ramon F Herrera, Jun 8, 2012
    #6
  7. Ramon F Herrera

    Simon Wright Guest

    Ramon F Herrera <> writes:

    > On Jun 8, 11:13 am, Simon Wright <> wrote:
    >> Ramon F Herrera <> writes:
    >>
    >> > I have been using two XPath implementations, the one from Xerces-C
    >> > (for fast performance with elemental expressions) and XQilla (for full
    >> > expression support).  At this point I have some expressions that must
    >> > be evaluated in two steps.

    >>
    >> > First query:
    >> > /root/table[@tagname='intermediate_joints']

    >>
    >> > The tables (nodes) produced by that query should be set as the new
    >> > context before the next XPath queries are performed.

    >>
    >> > How do I set up the context?

    >>
    >> You can save the first query in a variable:
    >>
    >>   <xsl:variable
    >>     name="foo"
    >>     select="/root/table[@tagname='intermediate_joints']"/>
    >>
    >> and then further selections can be written using
    >>
    >>   select="$foo/more/selections"

    >
    > Thanks, Simon:
    >
    > It seems to me that your suggestion is equivalent to the one in the
    > thread "".
    >
    > /root/table[@tagname='intermediate_joints']/intermediate_joints/
    > joint_label
    >
    > That solution is not good when you have a lot of similar tables: You
    > get too many hits, and you cannot distinguish which one came from what
    > ancestor.
    >
    > I just learned (in this NG) about "context", something for which I
    > never had any need. I was using it only once without even being aware.
    >
    > I need to perform an XPath query relative to the current context. Path
    > concatenation will not do.


    I don't think I understand what you mean by context. But then I'm used
    to using XPath in Saxon and in XIA (XPath-in-Ada).

    In XIA, the query
    "/root/table[@tagname='intermediate_joints']/intermediate_joints/joint_label"
    would produce a DOM.Core.Node_List; for each Node in that Node_List, you
    could execute a query "../../name" to extract a Node_List containing
    (hopefully) one element, the /root/table/name (I made this up) for the
    particular table that is the ancestor of the joint_label.

    Or you could make a query "/root/table[@tagname='intermediate_joints']"
    and for each Node in that Node_List you'd query for "name" (one result)
    and for "intermediate_joints/joint_label" (multiple results), all
    belonging to 'this' Node.

    The second sounds more like what you're trying to do??? if not, I'm
    stuck.
     
    Simon Wright, Jun 8, 2012
    #7
  8. On Jun 8, 4:40 pm, Simon Wright <> wrote:
    > Ramon F Herrera <> writes:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > On Jun 8, 11:13 am, Simon Wright <> wrote:
    > >> Ramon F Herrera <> writes:

    >
    > >> > I have been using two XPath implementations, the one from Xerces-C
    > >> > (for fast performance with elemental expressions) and XQilla (for full
    > >> > expression support).  At this point I have some expressions that must
    > >> > be evaluated in two steps.

    >
    > >> > First query:
    > >> > /root/table[@tagname='intermediate_joints']

    >
    > >> > The tables (nodes) produced by that query should be set as the new
    > >> > context before the next XPath queries are performed.

    >
    > >> > How do I set up the context?

    >
    > >> You can save the first query in a variable:

    >
    > >>   <xsl:variable
    > >>     name="foo"
    > >>     select="/root/table[@tagname='intermediate_joints']"/>

    >
    > >> and then further selections can be written using

    >
    > >>   select="$foo/more/selections"

    >
    > > Thanks, Simon:

    >
    > > It seems to me that your suggestion is equivalent to the one in the
    > > thread "".

    >
    > > /root/table[@tagname='intermediate_joints']/intermediate_joints/
    > > joint_label

    >
    > > That solution is not good when you have a lot of similar tables: You
    > > get too many hits, and you cannot distinguish which one came from what
    > > ancestor.

    >
    > > I just learned (in this NG) about "context", something for which I
    > > never had any need. I was using it only once without even being aware.

    >
    > > I need to perform an XPath query relative to the current context. Path
    > > concatenation will not do.

    >


    > I don't think I understand what you mean by context.


    Well, you are not alone. I had no idea until a couple days ago,
    either :)

    ....when nice folks in this NG told me about it.

    I surmise than in a huge/large percentage of cases the context is the
    root and it remains fixed, because XQueries can almost always be
    unambiguously defined from the top.

    Here's the source code that I am using.

    This is context-less:

    http://xqilla.sourceforge.net/docs/simple-api/simple-basic_8cpp-example.html

    and since this one uses an actual XML file, it needs a real context,
    which is initially set to the top/root of the document:

    http://xqilla.sourceforge.net/docs/simple-api/simple-context-item_8cpp-example.html

    "Context" is like the current default/working directory in a
    filesystem.

    -Ramon
     
    Ramon F. Herrera, Jun 8, 2012
    #8
  9. Ramon F Herrera

    Simon Wright Guest

    "Ramon F. Herrera" <> writes:

    > which is initially set to the top/root of the document:
    >
    > http://xqilla.sourceforge.net/docs/simple-api/simple-context-item_8cpp-example.html


    Here is the outer context being set to the top of the document:

    // Parse a document, and set it as the context item
    Sequence seq = context->resolveDocument(X("foo.xml"));
    if(!seq.isEmpty() && seq.first()->isNode()) {
    context->setContextItem(seq.first());
    context->setContextPosition(1);
    context->setContextSize(1);
    }

    // Execute the query, using the context
    Result result = query->execute(context);

    Result is a sequence of "items" (in my terminology, Nodes).

    // Iterate over the results, printing them
    Item::ptr item;
    while(item = result->next(context)) {

    At this point, I'd expect you to be able to convert 'item' from the
    generalized Item::ptr to a Node, and create a local DynamicContext
    object (called something other than 'context', to avoid confusion, of
    course) and set it up in the same way as the outer context was set up
    above, but referring to this Node. You'd then set up the appropriate
    XQQuery and execute it on this local context.

    I'm afraid I don't know C++ or XQilla well enough to say how to do the
    crucial step of converting item to a Node. Maybe there's an
    Item::asNode() operation? Maybe you don't need to? Maybe it's as simple
    as

    if (item->isNode()) {
    // create query q, context c
    c->setContextItem(item); // here where you change context
    // set position, size???
    Result r = q->execute(c);
    // process result
    }
     
    Simon Wright, Jun 9, 2012
    #9
  10. On 6/8/2012 2:34 PM, Ramon F Herrera wrote:
    > XML seems to be a area where plenty of software is written only to be
    > abandoned (Xerces, Xqilla, Xalan, etc.)


    This is partly an artifact of your choice of C++. The XML community in
    Java is considerably more active.

    But, yeah, the downside of open-source software is that it is generally
    supported only on an as-time-is-available basis. And these days there's
    a lot less time available for most of us.

    Good luck with libxml2. I've heard mixed reviews.

    --
    Joe Kesselman,
    http://www.love-song-productions.com/people/keshlam/index.html

    {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
    /\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
     
    Joe Kesselman, Jun 10, 2012
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cvissy
    Replies:
    0
    Views:
    623
    cvissy
    Nov 16, 2004
  2. Porky Pig Jr
    Replies:
    3
    Views:
    1,077
    Fuzzyman
    May 12, 2004
  3. CoreyWhite
    Replies:
    1
    Views:
    675
    JohnQ
    Mar 31, 2007
  4. Alexander
    Replies:
    20
    Views:
    1,072
    BGB / cr88192
    Sep 11, 2010
  5. Norah Jones
    Replies:
    0
    Views:
    100
    Norah Jones
    Apr 7, 2014
Loading...

Share This Page