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

  • Thread starter Ramon F Herrera
  • Start date
R

Ramon F Herrera

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
 
S

Simon Wright

Ramon F Herrera said:
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"
 
R

Ramon F Herrera

Ramon F Herrera said:
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
 
R

Ramon F Herrera

Ramon F Herrera said:
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
 
J

Joe Kesselman

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."
 
R

Ramon F Herrera

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
 
S

Simon Wright

Ramon F Herrera said:
Ramon F Herrera said:
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.
 
R

Ramon F. Herrera

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
 
S

Simon Wright

Ramon F. Herrera said:

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
}
 
J

Joe Kesselman

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."
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top