xsl-list
[Top] [All Lists]

RE: How to get out the document()-file

2004-07-27 09:13:05
From: Roger [mailto:oxyme(_at_)wanadoo(_dot_)nl]

I have the following problem. I have an external xml-data-document
(list.xml) from which I read a list of elements using the document()
function. I want use a for-each-selection for all those elements, to
display them all in a row. Inside the for-each, I need to use data
from
the original xml-data-document (data.xml).

Now I don't get any data displayed from the data.xml document inside
the
for-each. I've used an absolute path to get to the root of the
data.xml
file, but that doesn't seem to work. I've checked the absolute path
outside of the for-each, and there it works fine. So I suppose I'm
trapped into the list.xml document. How do I get out? Any ideas?

This is a common situation.  While you are within the for-each block,
the context comes from the external document, so path expressions refer
to it, not to the original source document.  The solution is to create a
global variable for the source document, like this -

<xsl:variable name='source-doc' select='/'/>

You can use this variable, which contains all the nodes from the source
document, within the for-each loop.  Note that you may want to be more
specific than "/", depending on your needs.

Cheers,

Tom P


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