You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Jo...@telia.se on 2001/03/26 16:33:07 UTC

Prefix namexpace in xpaths don't work in Xalan 2.0.1!

Hi!

I'm a Xalan 2 beginner and my fist problem is that namespace-prefix 
don't work in my xpaths.

Example doc (a cut from http://www.w3.org/TR/REC-rdf-syntax/#examples):
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:dc="http://purl.org/metadata/dublin_core#"> 
  <rdf:Description about="http://www.foo.com/cool.html"> 
    <dc:Creator>
      <rdf:Seq ID="CreatorsAlphabeticalBySurname">
	<rdf:li>Mary Andrew</rdf:li>
	<rdf:li>Jacky Crystal</rdf:li>
      </rdf:Seq>
    </dc:Creator>
  </rdf:Description> 
</rdf:RDF>
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:dc="http://purl.org/metadata/dublin_core#"> 
  <rdf:Description about="http://www.foo.com/cool.html"> 
    <dc:Creator>
      <rdf:Seq ID="CreatorsAlphabeticalBySurname">
	<rdf:li>Mary Andrew</rdf:li>
	<rdf:li>Jacky Crystal</rdf:li>
      </rdf:Seq>
    </dc:Creator>
  </rdf:Description> 
</rdf:RDF>


Not with prefix:

>java ApplyXPath foo_rdf.rdf /RDF/Description/Creator
Loading classes, parsing foo_rdf.rdf, and setting up serializer
Querying DOM using /RDF/Description/Creator
<output>
<dc:Creator>
      <rdf:Seq ID="CreatorsAlphabeticalBySurname">
        <rdf:li>Mary Andrew</rdf:li>
        <rdf:li>Jacky Crystal</rdf:li>
      </rdf:Seq>
    </dc:Creator>
</output>

With prefix:

>java ApplyXPath foo_rdf.rdf /RDF/Description/dc:Creator
Loading classes, parsing foo_rdf.rdf, and setting up serializer
Querying DOM using /RDF/Description/dc:Creator
<output>
</output>

I have also tried the XPathApi (same call sequense as in ApplyPath) 
with same effect.

Is it a bug? or can I modifie the call to XPathAPI to get it to work?

I have not reported this as a bug. yet....


Regards John Landeborg


Re: Prefix namexpace in xpaths don't work in Xalan 2.0.1!

Posted by Gary L Peskin <ga...@firstech.com>.
John.G.Landeborg@telia.se wrote:
> 
> Hi!
> 
> I'm a Xalan 2 beginner and my fist problem is that namespace-prefix
> don't work in my xpaths.
> 
> Example doc (a cut from http://www.w3.org/TR/REC-rdf-syntax/#examples):
> <rdf:RDF
>   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>   xmlns:dc="http://purl.org/metadata/dublin_core#">
>   <rdf:Description about="http://www.foo.com/cool.html">
>     <dc:Creator>
>       <rdf:Seq ID="CreatorsAlphabeticalBySurname">
>         <rdf:li>Mary Andrew</rdf:li>
>         <rdf:li>Jacky Crystal</rdf:li>
>       </rdf:Seq>
>     </dc:Creator>
>   </rdf:Description>
> </rdf:RDF>
> 
> Not with prefix:
> 
> >java ApplyXPath foo_rdf.rdf /RDF/Description/Creator
> Loading classes, parsing foo_rdf.rdf, and setting up serializer
> Querying DOM using /RDF/Description/Creator
> <output>
> <dc:Creator>
>       <rdf:Seq ID="CreatorsAlphabeticalBySurname">
>         <rdf:li>Mary Andrew</rdf:li>
>         <rdf:li>Jacky Crystal</rdf:li>
>       </rdf:Seq>
>     </dc:Creator>
> </output>
> 
> With prefix:
> 
> >java ApplyXPath foo_rdf.rdf /RDF/Description/dc:Creator
> Loading classes, parsing foo_rdf.rdf, and setting up serializer
> Querying DOM using /RDF/Description/dc:Creator
> <output>
> </output>
> 
> I have also tried the XPathApi (same call sequense as in ApplyPath)
> with same effect.
> 
> Is it a bug? or can I modifie the call to XPathAPI to get it to work?
> 
> I have not reported this as a bug. yet....

John --

I agree that this is very confusing.  The problem is that ApplyXPath
does not use the namespaces declared in the document because of the way
that it calls XPathAPI.  It uses the two argument from of the call:

      NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath);

and this causes namespaces to be resolved against the "doc" node which,
of course, has no namespaces in scope.  You could modify the line to do
something like:

      NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath,
doc.getDocumentElement());

which I think will do what you want.

Gary