Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Need to learn how to set up the context in XQuilla and/or Xerces-C

Reply
Thread Tools

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

 
 
Ramon F Herrera
Guest
Posts: n/a
 
      06-08-2012

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/s...p-example.html
 
Reply With Quote
 
 
 
 
Simon Wright
Guest
Posts: n/a
 
      06-08-2012
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"
 
Reply With Quote
 
 
 
 
Ramon F Herrera
Guest
Posts: n/a
 
      06-08-2012
On Jun 8, 11:13*am, Simon Wright <si...@pushface.org> wrote:
> Ramon F Herrera <ra...@conexus.net> 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

 
Reply With Quote
 
Ramon F Herrera
Guest
Posts: n/a
 
      06-08-2012
On Jun 8, 11:13*am, Simon Wright <si...@pushface.org> wrote:
> Ramon F Herrera <ra...@conexus.net> 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

 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      06-08-2012
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...lam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 
Reply With Quote
 
Ramon F Herrera
Guest
Posts: n/a
 
      06-08-2012
On Jun 8, 1:09*pm, Joe Kesselman <keshlam.cat.nos...@verizon.net>
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/s.../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
 
Reply With Quote
 
Simon Wright
Guest
Posts: n/a
 
      06-08-2012
Ramon F Herrera <> writes:

> On Jun 8, 11:13Â*am, Simon Wright <si...@pushface.org> wrote:
>> Ramon F Herrera <ra...@conexus.net> 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.
 
Reply With Quote
 
Ramon F. Herrera
Guest
Posts: n/a
 
      06-08-2012
On Jun 8, 4:40*pm, Simon Wright <si...@pushface.org> wrote:
> Ramon F Herrera <ra...@conexus.net> writes:
>
>
>
>
>
>
>
>
>
> > On Jun 8, 11:13*am, Simon Wright <si...@pushface.org> wrote:
> >> Ramon F Herrera <ra...@conexus.net> 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/s...p-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/s...p-example.html

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

-Ramon
 
Reply With Quote
 
Simon Wright
Guest
Posts: n/a
 
      06-08-2012
"Ramon F. Herrera" <> writes:

> which is initially set to the top/root of the document:
>
> http://xqilla.sourceforge.net/docs/s...p-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:tr item;
while(item = result->next(context)) {

At this point, I'd expect you to be able to convert 'item' from the
generalized Item:tr 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
}
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      06-10-2012
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...lam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Some information for the one who decided to learn C++, and now wantsto learn at least a bit of C? Alexander C Programming 20 09-11-2010 01:04 AM
Learn the language before you learn the GUI. CoreyWhite C++ 1 03-31-2007 08:56 PM
Context.Items vs Context.Handler (passing values between pages) VS_NET_DEV ASP .Net 2 05-25-2004 01:16 PM
newbie question: should I learn TKinter or skip it and learn more advanced toolkit? Porky Pig Jr Python 3 05-12-2004 08:58 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57