You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Hookom, Jacob John" <ho...@uwec.edu> on 2002/11/20 17:12:50 UTC

Referencing multiple doms for XPath

Hi All,
 
After reading some XSL examples pertaining to the decomposition of XML documents, I'm wondering if you can do the same in the DOM- moreover releated to XPath queries?
 
Example:
articles.xml
<articles>
     <article id="2">
          <author idref="1"/>
          <author idref="2"/>
     </article>
</articles>
 
authors.xml
<authors>
     <author id="1" email="jacob@xml.com"/>
     <author id="2" email="nate@xml.com"/>
</authors>
 
With the above given, is there a way to say, take the articles.xml, reference the authors.xml and then run an XPath query to ask for all the author's emails for an article?  And do I have to define a DTD to declare the attribute type of id to be an ID?
 
Best Regards,
Jacob
 
 

Re: Referencing multiple doms for XPath

Posted by Joseph Kesselman <ke...@us.ibm.com>.
>With the above given, is there a way to say, take the articles.xml, 
reference the authors.xml >and then run an XPath query to ask for all the 
author's emails for an article?  And do I have >to define a DTD to declare 
the attribute type of id to be an ID?

Let me try breaking this down into separate questions.


An attribute must be declared as an ID in the DTD in order to be 
recognized as an ID in XPath. Of course if you happen to know the name of 
the attribute which will be used as an ID on a particular element, you can 
search based on that combination of element/attribute names instead, 
though this may be less efficient since we wouldn't be able to use a quick 
lookup table of IDs.


A stylesheet can reference additional documents by using the document() 
function to retrieve them by their URI. So if you know that the idrefs in 
articles.xml refer to authors.xml, you could use document() to load the 
latter and then search within it.


You also asked "I'm wondering if you can do the same in the DOM". This 
gets more complicated. Our APIs do allow us to read stylesheets and source 
documents from a DOM, or to write to a DOM as our output. But finding 
*additional* DOM trees isn't something that XSLT understands.

There are a number of workarounds. One would be to write an extension 
function which takes some parameter that tells it which DOM you're looking 
for and looks it up in a pre-established table of DOMs. Another might be 
to plug in a URI resolver which would check that table first and return 
data from the appropriate DOM rather than from a file -- though I think in 
our current code this would be less efficient than the extension solution. 
A third option, which I haven't tried, is that it _may_ be possible to 
pass a DOM tree into Xalan via the Transformer.setParameter() call... but 
I'm not sure whether Xalan would recognize the DOM Node as representing a 
searchable document tree in this case; I'd have to try it or work my way 
through the code to be sure.


If I've misunderstood your question, please clarify and I'll try again.

______________________________________
Joe Kesselman  / IBM Research