Re: document() revisited

Subject: Re: document() revisited
From: Steve Tinney <stinney@xxxxxxxxxxxxx>
Date: Wed, 16 Feb 2000 08:29:52 -0500
> <mother>
>   <file>files\overview.html</file>
>   <file>files\book1\page1.html</file>
>   <file>files\book1\chap1\page2.html</file>
>   <file>files\book2\page1.html</file>
>   <file>files\book2\chap1\page2.html</file>
> </mother>
> 
> How can I use XSL to enter each listed file,
> manipulate it and copy the result onto itself,
> thus retaining the file names and directory structure?

You would need to use document(), as you already realize, in conjunction
with a processor that has at least an output extension, and possibly a
nodeset extension also (depending on what you want to do).  You would
need to be sure that after a document() call, the processor closed the
file (i.e., do some testing with unimportant data first or, better, read
the source for your processor).  So, the structure would be something
like this:

    <xsl:template match="file">
      <xsl:variable name="pathname" select="."/>
      <xsl:variable name="contents" select="document($pathname)"/>
      <xsl:variable name="newcontents-rtf">
        ... rewrite $contents here ...
      </xsl:variable>
      ... possibly do further transforms here ...
      <saxon:output file="$pathname" method="xml" encoding="utf-8">
        <xsl:copy-of select="$newcontents-rtf"/>
      </saxon:output>
    </xsl:template>

You probably need to ensure that you reference $contents before doing
the file open for the new output because most(? some?) processors do
lazy evaluation of the select expressions.

 Steve


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


Current Thread