This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: multiple output files within a recursive template


[snip]

> The task of this template is it to divide the source document into 2
> parts/files, the first 1500 characters and the rest. Basically it works quite
> fine. The only problem is that Saxon 5.5.1 overwrites existing files instead of
> appending the output to the existing file, so that only the output of the last
> temaple match is written to the file(s).
> 
> Now I'd like to know if there is a possibility to tell Saxon (or any other XSL
> transformation tool) to append output at existing files instead of overwriting
> them or if there is another way to solve the problem?
> 
> Hope somebody got a hint for me.

Using 4XSLT, your template would look like

<xsl:template name="Counter"
              xmlns:ft="http://namespaces.4suite.org/xpath/extensions">
   <xsl:param name="list"/>
   <xsl:param name="currentlength" select="0"/>
   <xsl:if test="string($list)!=''">
      <xsl:choose>
      <xsl:when test="($currentlength + string-length($list[1])) &lt; 1500">
         <ft:write-file name="part1.xml" overwrite="no">
            <xsl:value-of select="$list[1]"/>
         </ft:write-file>
      </xsl:when>
      <xsl:otherwise>
         <ft:write-file name="part2.xml" overwrite="no">
            <xsl:value-of select="$paralist[1]"/>
         </ft:write-file>
      </xsl:otherwise>
      </xsl:choose>
   </xsl:if>

   <xsl:call-template name="Counter">
   <xsl:with-param name="list" select="$list[position()!=1]"/>
   <xsl:with-param name="currentlength" select="$currentlength +
string-length($list[1])"/>
   </xsl:call-template>
</xsl:template>

Notice the "overwrite" attribute.  Pretty self-explanatory.  However, the 
default in 4XSLT is _not_ to overwrite so in this case, it's not really 
necessary.


-- 
Uche Ogbuji                               Principal Consultant
uche.ogbuji@fourthought.com               +1 303 583 9900 x 101
Fourthought, Inc.                         http://Fourthought.com 
4735 East Walnut St, Ste. C, Boulder, CO 80301-2537, USA
Software-engineering, knowledge-management, XML, CORBA, Linux, Python



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]