Copy files (.html, .xml) to output folder

Description

Goal is to enable users to add files to the Document Manager and then have those files copied into the appropriate location in their output folder during an ePublisher generation cycle.

This example is based upon one user's need to copy a metadata.xml file into the output folder at a designated location as well as .html files.

Override for files.xsl

One way to accomplish this task is as follows.

  1. Configure your project to accept the target document extension, e.g. .html, under "Project Settings...", "File Mappings". Just map it to the XML adapter.

  2. Add the files to the Document Manager.
  3. Create an override for "Transforms\files.xsl" and add the following code at the bottom of the "Files" call template (Cut/paste code beginning after the "Baggage" comment):
     <xsl:template name="Files">
      ...
      <xsl:param name="ParamGroupID" />
      ...
    
       <!-- Baggage -->
       <!--         -->
       ...
    
    <!-- START CUT/PASTE HERE -->
       <!-- Copy Documents -->
       <!--                -->
       <xsl:for-each select="$GlobalProject/wwproject:Project/wwproject:Groups/wwproject:Group[@GroupID = $ParamGroupID]//wwproject:Document">
        <xsl:variable name="VarDocument" select="." />
    
        <!-- Extract file info -->
        <!--                   -->
        <xsl:variable name="VarAbsoluteDocumentPath" select="wwfilesystem:Combine(wwprojext:GetProjectDirectoryPath(), $VarDocument/@Path)" />
        <xsl:variable name="VarFileName" select="wwfilesystem:GetFileName($VarAbsoluteDocumentPath)" />
        <xsl:variable name="VarExtension" select="wwfilesystem:GetExtension($VarAbsoluteDocumentPath)" />
    
        <!-- Copy? -->
        <!--       -->
        <xsl:variable name="VarCopyAsText">
         <xsl:choose>
          <!-- metadata.xml -->
          <!--              -->
          <xsl:when test="$VarFileName = 'metadata.xml'">
           <xsl:value-of select="true()" />
          </xsl:when>
    
          <!-- .html -->
          <!--       -->
          <xsl:when test="$VarExtension = '.html'">
           <xsl:value-of select="true()" />
          </xsl:when>
    
          <!-- Skip it! -->
          <!--          -->
          <xsl:otherwise>
           <xsl:value-of select="false()" />
          </xsl:otherwise>
         </xsl:choose>
        </xsl:variable>
        <xsl:variable name="VarCopy" select="$VarCopyAsText = 'true'" />
    
        <!-- Copy file if requested -->
        <!--                        -->
        <xsl:if test="$VarCopy">
         <xsl:variable name="VarOutputDirectoryPath" select="wwfilesystem:Combine(wwprojext:GetTargetOutputDirectoryPath(), wwprojext:GetDocumentGroupPath($VarDocument/@DocumentID))" />
         <xsl:variable name="VarOutputPath" select="wwfilesystem:Combine($VarOutputDirectoryPath, $VarFileName)" />
    
         <!-- Emit copy file entry -->
         <!--                      -->
         <wwsplits:File groupID="{$ParamGroupID}" documentID="" id="" type="{$ParameterCopySplitFileType}" source="{$VarAbsoluteDocumentPath}" path="{$VarOutputPath}" title="" />
        </xsl:if>
       </xsl:for-each>
    <!-- END CUT/PASTE HERE -->
      </wwsplits:Splits>
     </xsl:template>
    </xsl:stylesheet>
  4. Adjust the file filters as necessary for your code.

NOTE: Currently, this approach will report conversion errors on your copy extensions as ePublisher will fail while attempting to process them via the standard conversion operations.

DevCenter/Projects/Copy files (.html, .xml) to output folder (last edited 2010-04-26 18:02:02 by BenAllums)