Saving path definition


ATTENTION
Please note the following restrictions before using this document function:

  • Due to Word's own various save dialogs, it cannot be guaranteed that the defined file names and paths will take effect. Example: In the case of Microsoft 365 this works with the save dialog via key F12, but not with the new one at the new save menu under Datei → Speichern unter jedoch nicht.

This document function is used to suggest a name and a file location when saving the document in the standard save dialog. It is possible to compose the file name using profile data or document parameters. This is done in the configuration by accessing elements from the CustomXMLPart via XSLT and XPath.


Basic configuration

Here is a simple example configuration:

<SavePathConfiguration> <SaveNewDocumentOnOpen>false</SaveNewDocumentOnOpen> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" /> <!-- parameters from outside this stylesheet can be passed by an interface they are not used in this configuration --> <xsl:param name="filename" /> <xsl:param name="path" /> <xsl:param name="pathAndFilename" /> <xsl:param name="targetFolderFileList" /> <xsl:template match="/"> <xsl:variable name="Path" select="'C:\temp\'" /> <xsl:variable name="Filename" select="'Test_FileName'" /> <xsl:element name="DocumentFunction" namespace=""> <xsl:attribute name="name">SavePathDefinition</xsl:attribute> <xsl:element name="Path" namespace=""> <xsl:value-of select="concat($Path, $Filename,'.docx')" /> </xsl:element> <xsl:element name="CreateFolder" namespace="">false</xsl:element> </xsl:element> </xsl:template> </xsl:stylesheet> </SavePathConfiguration>

Resulta:

This causes the XSLT stylesheet to generate the following XML document:

<DocumentFunction name="SavePathDefinition"> <Path>C:\temp\Test_FileName.docx</Path> <CreateFolder>false</CreateFolder> </DocumentFunction>

This in turn is interpreted by OneOffixx to suggest the path "C:\temp" and the file name "Test_FileName.docx" in the save dialog. If the folder "C:\temp" does not exist, the folder should not be created in this example, because CreateFolder is set to false.

Save as-dialog:

The SaveNewDocumentOnOpen option can be used to define whether the user should be prompted to save after generating a document by displaying the save dialog.

Existing save paths and file names

CAUTION
In this configuration: If the save dialog is called for documents that have already been saved (e.g. TestDok.docx on the desktop), "Test_FileName" is suggested again under C:_temp\ and not the existing name at the existing location ("TestDok" on the desktop) as usual.


Extended configuration

Here is an example of a configuration with much more functionality:

<SavePathConfiguration> <SaveNewDocumentOnOpen>false</SaveNewDocumentOnOpen> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" /> <!-- parameters from outside this stylesheet can be passed by an interface they are not used in this configuration --> <xsl:param name="filename" /> <xsl:param name="path" /> <xsl:param name="pathAndFilename" /> <xsl:param name="targetFolderFileList" /> <xsl:template match="/"> <!-- add OneOffixx data --> <xsl:variable name="CustomElements.SavePathConfig.FileName" select="//Text[@id='CustomElements.SavePathConfig.FileName']" /> <xsl:variable name="CustomElements.SavePathConfig.Path" select="//Text[@id='CustomElements.SavePathConfig.Path']" /> <xsl:variable name="CustomElements.SavePathConfig.Path_NoSpace"> <xsl:if test="not($CustomElements.SavePathConfig.Path = ' ')"> <xsl:value-of select="$CustomElements.SavePathConfig.Path" /> </xsl:if> </xsl:variable> <xsl:variable name="CustomElements.SavePathConfig.UpdateFileName" select="//Text[@id='CustomElements.SavePathConfig.UpdateFileName']" /> <xsl:variable name="DocumentProperties.DocumentName" select="//Text[@id='DocumentProperties.DocumentName']" /> <xsl:variable name="DocumentProperties.SavePath" select="//Text[@id='DocumentProperties.SavePath']" /> <xsl:variable name="DocumentProperties.SavePath_NoSpace_PathOnly"> <xsl:if test="not($DocumentProperties.SavePath = ' ')"> <xsl:call-template name="substring-before-last"> <xsl:with-param name="string" select="$DocumentProperties.SavePath" /> <xsl:with-param name="delimiter" select="'\'" /> </xsl:call-template> <xsl:text>\</xsl:text> </xsl:if> </xsl:variable> <!-- evaluate boolean variables --> <xsl:variable name="documentWasSaved" select="boolean(normalize-space($DocumentProperties.SavePath_NoSpace_PathOnly) != '')" /> <xsl:variable name="updateFileName" select="boolean($CustomElements.SavePathConfig.UpdateFileName = 'true')" /> <xsl:variable name="keepExistingPath" select="boolean($documentWasSaved)" /> <xsl:variable name="keepExistingName" select="boolean($documentWasSaved and not($updateFileName))" /> <!-- set Path and Filename --> <xsl:variable name="Path"> <xsl:choose> <xsl:when test="$keepExistingPath"> <xsl:value-of select="$DocumentProperties.SavePath_NoSpace_PathOnly" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$CustomElements.SavePathConfig.Path_NoSpace" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="Filename"> <xsl:choose> <xsl:when test="$keepExistingName"> <xsl:value-of select="$DocumentProperties.DocumentName" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="translate($CustomElements.SavePathConfig.FileName, ' ', '_')" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- generate output XML --> <xsl:call-template name="generateOutputXML"> <xsl:with-param name="path" select="concat($Path, $Filename,'.docx')" /> </xsl:call-template> </xsl:template> <!-- generates the required output --> <xsl:template name="generateOutputXML"> <xsl:param name="path" /> <xsl:param name="createFolder" /> <xsl:element name="DocumentFunction" namespace=""> <xsl:attribute name="name">SavePathDefinition</xsl:attribute> <xsl:element name="Path" namespace=""> <xsl:value-of select="$path" /> </xsl:element> <xsl:element name="CreateFolder" namespace=""> <xsl:choose> <xsl:when test="$createFolder"> <xsl:value-of select="$createFolder" /> </xsl:when> <xsl:otherwise>false</xsl:otherwise> </xsl:choose> </xsl:element> </xsl:element> </xsl:template> <!-- determines the substring before last occurence of a specific delimiter --> <xsl:template name="substring-before-last"> <xsl:param name="string" /> <xsl:param name="delimiter" /> <xsl:choose> <xsl:when test="contains($string, $delimiter)"> <xsl:value-of select="substring-before($string, $delimiter)" /> <xsl:choose> <xsl:when test="contains(substring-after($string, $delimiter), $delimiter)"> <xsl:value-of select="$delimiter" /> </xsl:when> </xsl:choose> <xsl:call-template name="substring-before-last"> <xsl:with-param name="string" select="substring-after($string, $delimiter)" /> <xsl:with-param name="delimiter" select="$delimiter" /> </xsl:call-template> </xsl:when> </xsl:choose> </xsl:template> </xsl:stylesheet> </SavePathConfiguration>

The function translate(...) replaces all spaces with underscores ("_") in this example.

Inclusion in other document functions

Inclusion of scripts

The following scripts are accessed here:

The function of the individual scripts should be self-explanatory based on the name. These scripts must be available on any template that has the "Saving path definition" with this configuration attached.

Access to "Toolboxes in editor mode

In addition, these OneOffixx contents are accessed:

  • DocumentProperties.SavePath

  • DocumentProperties.DocumentName

For these contents to be available, the document function Toolboxes in editor mode must be attached (it is already attached in the layout template if there is a logo in the document).

Existing save paths and file names

The above inclusion of the existing save path and document name causes the existing save path and file name to be used for documents that have already been saved (see "Existing save paths and file names" at Basic Configuration above).

One problem that remains here, however: When a Word file is moved or renamed, the DocumentProperties.SavePath and DocumentProperties.DocumentName fields are not updated. In this case the old save path and file name is suggested, which was still current when the file was last saved.

PrimeSoft AG, Bahnhofstrasse 4, 8360 Eschlikon, Switzerland