Deploying custom baggage files

Our WebWorks Help template needs to be able to add static files on a per-project basis after design-time; something like the Files directory, but stored with the source documents. At run-time, I determine if the source directory exists and copy any files from it with CopyDirectoryFiles(). This adds the files to the staging directory, but they do not get deployed. I have added code to set the deploy attribute to true (per Ben's suggestion, thanks!).

However, it only works code when there is a single group. When there are multiple groups, this code fails (see error below)

 <xsl:param name="GlobalInput" />
 <xsl:param name="GlobalProject" />
 <xsl:param name="GlobalPipelineName" />
 <xsl:param name="GlobalFiles" />

 <xsl:key name="wwfiles-files-by-type" match="wwfiles:File" use="@type" />
 <xsl:key name="wwsplits-split-by-documentid" match="wwsplits:Split" use="@documentID" />


 <xsl:variable name="GlobalActionChecksum">
  <xsl:variable name="VarTransformChecksums">
   <xsl:value-of select="concat(wwuri:AsFilePath('wwtransform:self'), ':', wwfilesystem:GetChecksum(wwuri:AsFilePath('wwtransform:self')))" />
  </xsl:variable>
  <xsl:value-of select="wwstring:MD5Checksum($VarTransformChecksums)" />
 </xsl:variable>

 <xsl:variable name="VarProjectChecksum" select="$GlobalProject/wwproject:Project/@ChangeID" />

 <!-- Main -->
 <!--      -->
 <xsl:template match="/">
  <wwfiles:Files version="1.0">

  <xsl:variable name="VarIgnore1Start" select="wwprogress:Start(1)" />
  <xsl:variable name="VarIgnore1Status" select="wwprogress:SetStatus('Generating Nuance files')" />

   <!-- Call directory copy -->
   <xsl:call-template name="CopyCustomFiles" />

   <xsl:variable name="VarIgnore1End" select="wwprogress:End()" />

   </wwfiles:Files>
 </xsl:template>
 
 <!-- Copy custom files -->
 <!--                        -->
 <xsl:template name="CopyCustomFiles">

   <xsl:variable name="VarProjectGroups" select="$GlobalProject/wwproject:Project/wwproject:Groups/wwproject:Group" />
   <xsl:for-each select="$VarProjectGroups">
     <xsl:variable name="VarProjectGroup" select="." />

     <!-- NOTE: Source is hard-coded -->
     <xsl:variable name="VarSourceDirectoryPath" select="'C:\_wwfiles\files'" />
     <xsl:variable name="VarOutputDirectoryPath" select="wwfilesystem:Combine(wwprojext:GetTargetOutputDirectoryPath(), wwprojext:GetGroupName($VarProjectGroup/@GroupID) )" />

     <xsl:if test="wwfilesystem:DirectoryExists($VarSourceDirectoryPath)" >
       <xsl:variable name="VarLogCopy" select="wwlog:Warning('[Custom] Copying files from ',$VarSourceDirectoryPath, ' to ', $VarOutputDirectoryPath)" />
       <xsl:variable name="VarCopiedFiles" select="wwfilesystem:CopyDirectoryFiles($VarSourceDirectoryPath,$VarOutputDirectoryPath)"  />
      
       <!-- Add them to the deploy list -->
       <xsl:for-each select="$VarCopiedFiles">
         <xsl:copy>
           <xsl:copy-of select="@*" />
             <xsl:attribute name="deploy">
               <xsl:text>true</xsl:text>
             </xsl:attribute>
           <xsl:copy-of select="./*" />
         </xsl:copy>
       </xsl:for-each>

     </xsl:if>
   </xsl:for-each>
 </xsl:template>

This file is called directly from the .wfmt

  <Pipeline name="nuan_files">
   <Depends pipeline="page" />
   <Depends pipeline="MergeFiles" />
   <Stage type="xsl" action="wwformat:Transforms/copy_files.xsl">
   </Stage>
  </Pipeline>

Here is the error I get:

[Warning] [Custom] Copying files from C:\_wwfiles\files to C:\webworks\wwhelp_test2\Output\Target 1\First_group
[Warning] [Custom] Copying files from C:\_wwfiles\files to C:\webworks\wwhelp_test2\Output\Target 1\Second_group
[Error] An error occurred in pipeline 'custom_files' while processing stage transform 'wwformat:Transforms/custom_files.xsl'.
[Error] Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added.

Why is this failing?

2011-06-13

Mike,

Where is this template being invoked? It matters only because the <wwfiles:File> elements must be emitted at the top-level of your root match template. Can you attach the full override .xsl file?

BenAllums

2011-06-13

Ben,

I updated the list to include everything except the xsl:stylesheet declaration. That's all there is to it, and it is called from the .wfmt. And here is the attachment nuan_files.xsl.

-- Mike

2011-06-14

Mike,

Please review the attached project Baggage Files.2011-06-14.zip. It contains further changes to your original transform which add the deploy attribute and update the groupID attribute.

I found two issues:

  1. The <Depends> declaration in the format.wwfmt file referenced the "page" pipeline rather than the "Page" pipeline.

  2. The <xsl:for-each> loop selected $CopiedFiles rather than $VarCopiedFiles/wwfiles:Files/wwfiles:File. The first one is a File Info document, so when the root element was emitted, things were processed in an unexpected order.

2011-06-15

Ben,

I suspected that for-each argument was the problem. I tried playing with it but could not get the namespace right. Your clarification is clear-as-a-bell (and helps explain namespace too). Thanks for the help!!!


CategoryHowto

DevCenter/Projects/Deploying custom baggage (last edited 2011-06-15 15:33:22 by MikeHedblom)