xsl-list
[Top] [All Lists]

Pass a DOM as an XSLT parameter?

2003-12-14 17:04:40
I've been asked to process two XML documents with one XSLT stylesheet. One 
document exists in the file system and the other exists in memory as the result 
of a SQL Server 2000 "for XML" query. In an ideal world, I would write a 
stylesheet to process the file-system XML document and bring the in-memory XML 
document into the transformation via the document() function. Since the 
document() function takes as a parameter a URI, and since I can't think of a 
way to give a URI to the in-memory document, I'm stumped. I've thought of 
creating a DOM from the in-memory XML and passing the DOM as a parameter, but 
I'm pretty sure that won't work. So now I'm thinking of capturing the in-memory 
XML in a string and passing the string to the XSLT as a parameter and 
reconstituting the tree inside the XSLT as a variable using a nodeset() 
function, but I've never done that and I'm fuzzy on it.

I have tried "doing it backwards" by writing the stylesheet so that it will 
process the in-memory XML and accessing the file-system XML via the document() 
function, but I'm getting hoplessly confused at trying to reference the the 
contents of the document()-created document. It's even hard to write a sentence 
that explains that clearly.

Here is a model of the in-memory document:

<exhibits>
  <chapter1>stuff</chapter1>
  <chapter3>some more stuff</chapter3>
</exhibits>

Here is a model of the file-system document:

<book>
  <front-matter />
  <chapters>
    <chapter>
      <chapter-num>1</chapter-num>
      <exhibit-ref>chapter1</exhibit-ref>
    </chapter>
    <chapter>
      <chapter-num>2</chapter-num>
      <exhibit-ref>chapter2</exhibit-ref>
    </chapter>
    <chapter>
      <chapter-num>3</chapter-num>
      <exhibit-ref>chapter3</exhibit-ref>
    </chapter>
  </chapters>
  <index />
</book>

One problem I'm facing is that the in-memory document does not contain elements 
matching every element in the file-system document and the file-system document 
needs to be the driver of the process even though it's not the file set up as 
the one to be directly processed by the transformation. I think that if I 
re-write the stylesheet so that it processes the file-system XML and pass the 
in-memory XML documents contents as a string to the XSLT (and re-constitute it 
as a node tree using the nodeset() function) I can solve the problem simply.


The processor is MSXML4. The context of the transformation is an ASP page in 
which the appropriate COM objects are created. Can anyone give me some guidance 
on this?

-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>