Hi Evan et al,
I am having a problem with document() as well.
Assume I have a file "file.xml", which I will generate occasionally and want
to merge into my document. The current XSLT (call it "current.xsl") doesn't
call this file right now; the main file is named, oh, "main.xml".
The file "file.xml" looks like this:
<file>
<first>the first element</first>
<second>the second element</second>
<third>the third element</third>
</file>
How do I call the document() function to get the individual nodes out of the
file "file.xml" to be used by FOP in "current.xsl"?
I tried a merge, but it basically gave me all of both files, then formatted
according to the "current.xsl". Do I need to create a second style sheet to
use with xsl:apply-templates? The information I found on the document()
function wasn't extensive.
Thanks,
Michael Gosselin
Athena Diagnostics, Inc.
Worcester, MA 01605
> -----Original Message-----
> From: Evan Lenz [mailto:evan@xxxxxxxxxxxx]
> Sent: Thursday, April 06, 2006 12:04 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: multiple source files map to multiple target files
>
> However, assuming you have the XML source file that contains
> the list of file names (URLs) that Michael mentioned, then a
> single invocation of
> document() can return all the root nodes from your XML files.
> (You don't have to do it individually for each one, e.g.,
> inside <xsl:for-each>.) And you don't need any extension
> functions to do this.
>
> Let's say you have a file named files.xml in the "config"
> directory that contains this:
>
> <files>
> <file>input/foo.xml</file>
> <file>input/bar.xml</file>
> <file>input/bat.xml</file>
> </files>
>
> Given the above document, the following expression will
> return a node-set containing three root nodes, corresponding
> to the three files listed.
>
> document(document('config/files.xml')/files/file)
>
> The file names are resolved relative to the location of
> files.xml by default, i.e. from the "config" directory in
> this case. The XSLT processor will look for an "input"
> directory inside the "config"
> directory. If you want to resolve them relative to your main
> source document (rather than from the "config" directory),
> then you could use the second (optional) argument to the
> document() function, like so:
>
> document(document('config/files.xml')/files/file, /)
>
> The / in the second argument tells the function to resolve
> the URLs relative to the base URI of the source document
> instead of from the config directory (where files.xml lives).
> The XSLT processor will look for an "input" directory inside
> whatever directory your source document came from.
>
> Finally, if you want to resolve them relative to the
> stylesheet's base URI, you would use this:
>
> document(document('config/files.xml')/files/file, document(''))
>
> The document('') in the second argument returns the root node
> of the stylesheet itself, so the relative URLs in files.xml
> are resolved relative to the base URI of the stylesheet. The
> XSLT processor will look for an "input" directory insider
> whatever directory your stylesheet came from.
>
> One more note: all the above examples assume that the
> "config" directory is in the same directory as the
> stylesheet. When you pass document() a string as the first
> argument it assumes the base URI of the stylesheet.
> When you pass it a node-set as the first argument (as we did
> with the <file> elements), then the function uses the base
> URI of each node in the node-set. In either case, you can
> override the base URI behavior by using the second optional
> argument (which must be a node-set). So, for example, if the
> "config" directory is in the same location as your source
> document, then you'd want to substitute this to grab the root
> node of files.xml in each of the above examples:
>
> document('config/files.xml', /)
|