You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Darren Wheatley <da...@tenjin.co.uk> on 2001/03/23 01:04:47 UTC

Xalan query

Hello,

Forgive me if this question is a little garbled, but I'm new to a lot of
this.

I want to be able to execute an XPATH expression, and then execute another
one for each node returned.

I'm using the XPathAPI class in Xalan to do this, but the problem I'm
finding is that the nodelist returned by the first call is simply a series
of pointers back into the original XML document, and what I really need is
for the XPath execution to produce a series of new document instances.

For example, consider the following XML file:

<people>
<manager>
<name>
    <firstname>Bob</firstname>
    <lastname>Smith</lastname>
</name>
<address>
    <town>St Albans</town>
    <county>Hertfordshire</county>
</address>
</manager>
<employee>
<name>
    <firstname>Jane</firstname>
    <lastname>Doe</lastname>
</name>
<address>
    <town>Hatfield</town>
    <county>Hertfordshire</county>
</address>
</employee>
<employee>
<name>
    <firstname>John</firstname>
    <lastname>Doe</lastname>
</name>
<address>
    <town>London Colney</town>
    <county>Hertfordshire</county>
</address>
</employee>
</people>

If my first XPath expression is:        //employee

which results in 2 nodes:

<employee>
<name>
    <firstname>Jane</firstname>
    <lastname>Doe</lastname>
</name>
<address>
    <town>Hatfield</town>
    <county>Hertfordshire</county>
</address>
</employee>

<employee>
<name>
    <firstname>John</firstname>
    <lastname>Doe</lastname>
</name>
<address>
    <town>London Colney</town>
    <county>Hertfordshire</county>
</address>
</employee>


However, executing a subsequent XPathAPI call using each of these nodes as
the context node, e.g. //firstname results in:

<firstname>Bob</firstname>
<firstname>Jane</firstname>
<firstname>John</firstname>

- as the XPath call reverts to DocumentRoot when it finds a "//" in an XPath
expression.

when I really only want the following:

<firstname>Jane</firstname>
<firstname>John</firstname>

So, my question is: how do I ensure that subsequent calls to the XPathAPI
methods use the context node as the document root? FYI, I've tried using
"importNode" and "clone" to create new copies of the nodes, but the XPathAPI
calls fail to find anything, I guess because DocumentRoot is set to NULL
following an importNode or clone call.

Cheers

Darren.




Re: Xalan query

Posted by Gary L Peskin <ga...@firstech.com>.
> Darren Wheatley wrote:
> So, my question is: how do I ensure that subsequent calls to the
> XPathAPI
> methods use the context node as the document root? FYI, I've tried
> using
> "importNode" and "clone" to create new copies of the nodes, but the
> XPathAPI
> calls fail to find anything, I guess because DocumentRoot is set to
> NULL
> following an importNode or clone call.

Darren --

I haven't put together an example to test this but won't an XPATH of
.//firstname (note the leading period) give you what you want?

Gary

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org